I have the following code:
In some cases its has no problem in going off and creating the update and the insert commands with the line:
While in other cases it will not create the commands, and gives the following error:
Any suggestions on how I can ensure that it creates the necessary commands every time?
Mike55.
Ok, according to a forum on VistaDB, my problem relates to the following lines:
Apparently what I am doing is changing the PRIMARY KEY while Editing. And this is not allowed.
So I have found the source of my problem, I must still get a solution to it.
Mike55.
Code:
Try
Dim sqlCommand As String
Dim cmdImport As New SqlCommand
Dim dcPKMembers(1) As DataColumn
sqlCommand = "SELECT Member_ID, Custom_ID, Surname, Forename, FullName, DOB, Title, MobileNumb, PhoneNumb, Addr1,Addr2, Town, County, " & _
" Role, Guardian1,Guardian1_Phone, Guardian2, Guardian2_Phone, Email,AdditionalInformation,CodePrefix, Country, PostCode," & _
"InternationalNumber, Sex," & _
"ImportReference,Custom1, Custom2, " & _
"Custom3, Custom4, Custom5, Custom6, Custom7, Custom8, Custom9, Custom10, Org_ID, Active " & _
"FROM Members WHERE Org_ID = " & mOrgId & ""
cmdImport.Connection = conSQL
cmdImport.CommandType = CommandType.Text
cmdImport.CommandText = sqlCommand
adpDatabase = New SqlDataAdapter
adpDatabase.SelectCommand = cmdImport
retry:
adpDatabase.Fill(dstDatabase, "Members")
Sets the primary Key on mobile number and fullname
dcPKMembers(0) = dstDatabase.Tables("Members").Columns("MobileNumb")
dcPKMembers(1) = dstDatabase.Tables("Members").Columns("FullName")
dstDatabase.Tables(0).PrimaryKey = dcPKMembers
Creates a new command builder
cmdbDatabase = New SqlCommandBuilder(adpDatabase)
In some cases its has no problem in going off and creating the update and the insert commands with the line:
Code:
cmdbDatabase = new SqlCommandBuilder(adpDatabase)
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.
Any suggestions on how I can ensure that it creates the necessary commands every time?
Mike55.
Ok, according to a forum on VistaDB, my problem relates to the following lines:
Code:
dcPKMembers(0) = dstDatabase.Tables("Members").Columns("MobileNumb")
dcPKMembers(1) = dstDatabase.Tables("Members").Columns("FullName")
dstDatabase.Tables(0).PrimaryKey = dcPKMembers
Apparently what I am doing is changing the PRIMARY KEY while Editing. And this is not allowed.
So I have found the source of my problem, I must still get a solution to it.
Mike55.
Last edited by a moderator: