Hi guys,
I hope somebody can help me with this.
I am developping a software with an Access 2003 database. I am trying to have an SNO field which should be an autonumber. Access 2003, as you probably know, has got limitation with Autonumber as it doesn't reuse the numbers. So I wrote code to do the check the total number of records before adding a new one, then increment it by one and add the new record against that. The problem I am facing is:
When deleting record, I cannot get the the software to re-number the records as it was. I am showing the records in a datagrid.
Example: If I have records: 1,2,3,4 & 5. Then I delete record 3 and add a new record, the new record will have the SNO 5 which is already exist. I wrote the following in a button click event. I can successfully re-number the recrods but I cannot save them in the database. If I click the button more than once, it throws the following erorr:
Concurrency Violation, the Update command affected 0 records.
DaCount is my Data Adapter
DSCont1 is my Dataset
Any help will be vey much appeciated !
I hope somebody can help me with this.
I am developping a software with an Access 2003 database. I am trying to have an SNO field which should be an autonumber. Access 2003, as you probably know, has got limitation with Autonumber as it doesn't reuse the numbers. So I wrote code to do the check the total number of records before adding a new one, then increment it by one and add the new record against that. The problem I am facing is:
When deleting record, I cannot get the the software to re-number the records as it was. I am showing the records in a datagrid.
Example: If I have records: 1,2,3,4 & 5. Then I delete record 3 and add a new record, the new record will have the SNO 5 which is already exist. I wrote the following in a button click event. I can successfully re-number the recrods but I cannot save them in the database. If I click the button more than once, it throws the following erorr:
Concurrency Violation, the Update command affected 0 records.
DaCount is my Data Adapter
DSCont1 is my Dataset
Any help will be vey much appeciated !
VB.NET:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
maxrows = DScont1.Tables("Container").Rows.Count
Dim x As Integer = 1
Dim c As Integer
'Ds1.Tables("CBMDB").Rows(inc).Item(0) = txtitemcode.Text
Dim cb As New OleDb.OleDbCommandBuilder(dacont)
Try
While x <= maxrows
DScont1.Tables("Container").Rows(c).Item(4) = x
cb.RefreshSchema()
x += 1
c += 1
End While
dacont.Update(DScont1, "Container")
cb.RefreshSchema()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Last edited by a moderator: