MaxSeqCmd = New OleDbCommand("SELECT @@IDENTITY", cn) AddHandler daSch.RowUpdated, New OleDbRowUpdatedEventHandler(AddressOf OnRowUpdated)
Private Sub OnRowUpdated(ByVal sender As Object, ByVal args As OleDbRowUpdatedEventArgs) Dim newID As Integer = 0
If args.Status = UpdateStatus.Continue AndAlso _ args.StatementType = StatementType.Insert Then Try newID = CInt(MaxSeqCmd.ExecuteScalar()) Debug.WriteLine(newID.ToString()) args.Row(F_SEQ) = newID args.Row.AcceptChanges() Catch ex As Exception MessageBox.Show("ExecuteScalar失敗") End Try
分類:[.NET]
お世話になります。
MSDNを参照して、MDBとDataTableのオートナンバーの相違(ずれ?)を
なくす為に、RowUpdatedイベントにてMDBからMAX値を取得して
設定するようにしたのですが、DataTable.Rows.Count=0の時、
正常に取得できません。Datasetで設定した、AutoIncrementSeed値(1)
のままになってしまいます。なぜでしょうか???
MaxSeqCmd = New OleDbCommand("SELECT @@IDENTITY", cn)
AddHandler daSch.RowUpdated, New OleDbRowUpdatedEventHandler(AddressOf OnRowUpdated)
Private Sub OnRowUpdated(ByVal sender As Object, ByVal args As OleDbRowUpdatedEventArgs)
Dim newID As Integer = 0
If args.Status = UpdateStatus.Continue AndAlso _
args.StatementType = StatementType.Insert Then
Try
newID = CInt(MaxSeqCmd.ExecuteScalar())
Debug.WriteLine(newID.ToString())
args.Row(F_SEQ) = newID
args.Row.AcceptChanges()
Catch ex As Exception
MessageBox.Show("ExecuteScalar失敗")
End Try
End If
End Sub