Updating Tables Not Working

T

Terry Burns

I have a datagrid bound to a table called tableEvents. I havesuccessfully
managed to manually code the insert, delete, select statewments, but the
update is giving me problems. I installed a handler which fires on row
changed. Th rowheader gets a little exclaimation mark in a red circle after
update is done to a cell and the rowstate changes to modified. But running
the update on the daEvents data adapter does not reflect the changes in the
source access database table. Here is the code, can anyone see where I might
be going wrong ?

'HANDLER
Private Sub Events_Row_Changed(ByVal sender As Object, ByVal e As
DataRowChangeEventArgs)

Try

daEvents.Update(tableEvents)

Catch ex As OleDbException

MessageBox.Show(ex.Message)

End Try

End Sub

'DURING INITIALISATION

AddHandler tableEvents.RowChanged, New DataRowChangeEventHandler(AddressOf
Events_Row_Changed)

'setup update command

cmd.CommandText = "UPDATE [Events] SET [Action] = ?, [Comments] = ?,
[EventType] = ?, [PersonIndex] = ? WHERE " & _

"([ID] = ?) AND ([Action] = ?) AND ([EventType] = ?) AND ([PersonIndex] = ?
OR ? IS NULL " & _

"AND [PersonIndex] IS NULL)"

cmd.Connection = con

cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Action",
System.Data.OleDb.OleDbType.VarWChar, 50, "Action"))

cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Comments",
System.Data.OleDb.OleDbType.VarWChar, 50, "Comments"))

cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("EventType",
System.Data.OleDb.OleDbType.VarWChar, 50, "EventType"))

cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("PersonIndex",
System.Data.OleDb.OleDbType.Integer, 0, "PersonIndex"))

cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_ID",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"ID", System.Data.DataRowVersion.Original, Nothing))

cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Action",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Action", System.Data.DataRowVersion.Original, Nothing))

cmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_EventType",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"EventType", System.Data.DataRowVersion.Original, Nothing))

cmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_PersonIndex",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"PersonIndex", System.Data.DataRowVersion.Original, Nothing))

cmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_PersonIndex1",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"PersonIndex", System.Data.DataRowVersion.Original, Nothing))

daEvents.UpdateCommand = cmd
 
T

Terry Burns

Concurrency violation: the UpdateCommand affected 0 records. occurs

Terry Burns said:
I have a datagrid bound to a table called tableEvents. I havesuccessfully
managed to manually code the insert, delete, select statewments, but the
update is giving me problems. I installed a handler which fires on row
changed. Th rowheader gets a little exclaimation mark in a red circle after
update is done to a cell and the rowstate changes to modified. But running
the update on the daEvents data adapter does not reflect the changes in the
source access database table. Here is the code, can anyone see where I might
be going wrong ?

'HANDLER
Private Sub Events_Row_Changed(ByVal sender As Object, ByVal e As
DataRowChangeEventArgs)

Try

daEvents.Update(tableEvents)

Catch ex As OleDbException

MessageBox.Show(ex.Message)

End Try

End Sub

'DURING INITIALISATION

AddHandler tableEvents.RowChanged, New DataRowChangeEventHandler(AddressOf
Events_Row_Changed)

'setup update command

cmd.CommandText = "UPDATE [Events] SET [Action] = ?, [Comments] = ?,
[EventType] = ?, [PersonIndex] = ? WHERE " & _

"([ID] = ?) AND ([Action] = ?) AND ([EventType] = ?) AND ([PersonIndex] = ?
OR ? IS NULL " & _

"AND [PersonIndex] IS NULL)"

cmd.Connection = con

cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Action",
System.Data.OleDb.OleDbType.VarWChar, 50, "Action"))

cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Comments",
System.Data.OleDb.OleDbType.VarWChar, 50, "Comments"))

cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("EventType",
System.Data.OleDb.OleDbType.VarWChar, 50, "EventType"))

cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("PersonIndex",
System.Data.OleDb.OleDbType.Integer, 0, "PersonIndex"))

cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_ID",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"ID", System.Data.DataRowVersion.Original, Nothing))

cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Action",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Action", System.Data.DataRowVersion.Original, Nothing))

cmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_EventType",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"EventType", System.Data.DataRowVersion.Original, Nothing))

cmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_PersonIndex",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"PersonIndex", System.Data.DataRowVersion.Original, Nothing))

cmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_PersonIndex1",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"PersonIndex", System.Data.DataRowVersion.Original, Nothing))

daEvents.UpdateCommand = cmd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top