Deleted rows wont delete

  • Thread starter Thread starter Terry Burns
  • Start date Start date
T

Terry Burns

This code is the contaxt menu handler assoc with a data grid, bound to
tableEvents and using daEvents adapter, the row deletes without error
message but does not delete at the access db, any ideas ??





Private Sub popUp_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim cc, sp As Point

Dim cmi As MenuItem

Dim TR As DataRow

Dim DT As DataTable

Dim DeleteCmd As New OleDbCommand

'open connection

con.Open()

cmi = DirectCast(sender, MenuItem)

Select Case cmi.Text

Case "Delete"

'Setup the Delete Command

DeleteCmd.CommandText = "DELETE FROM [Events] WHERE ([ID] = ?) AND ([Action]
= ?) AND ([EventType] = ?) AND ([Perso" & _

"nIndex] = ? OR ? IS NULL AND [PersonIndex] IS NULL)"

DeleteCmd.Connection = con

DeleteCmd.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))

DeleteCmd.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))

DeleteCmd.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))

DeleteCmd.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))

DeleteCmd.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))

tableEvents.Rows.RemoveAt(dgEvents.CurrentRowIndex)

daEvents.DeleteCommand = DeleteCmd

daEvents.Update(tableEvents)

Case "Add"



End Select

con.Close()
 
Terry,
The problem is with the line
tableEvents.Rows.RemoveAt(dgEvents.CurrentRowIndex)
RemoveAt completely removes a row from a collection and so there is nothing
to update
You should call the Delete method instead, which marks it for deletion.
Stephen
 
Thank you very much

Stephen Muecke said:
Terry,
The problem is with the line
tableEvents.Rows.RemoveAt(dgEvents.CurrentRowIndex)
RemoveAt completely removes a row from a collection and so there is nothing
to update
You should call the Delete method instead, which marks it for deletion.
Stephen

Terry Burns said:
This code is the contaxt menu handler assoc with a data grid, bound to
tableEvents and using daEvents adapter, the row deletes without error
message but does not delete at the access db, any ideas ??





Private Sub popUp_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim cc, sp As Point

Dim cmi As MenuItem

Dim TR As DataRow

Dim DT As DataTable

Dim DeleteCmd As New OleDbCommand

'open connection

con.Open()

cmi = DirectCast(sender, MenuItem)

Select Case cmi.Text

Case "Delete"

'Setup the Delete Command

DeleteCmd.CommandText = "DELETE FROM [Events] WHERE ([ID] = ?) AND ([Action]
= ?) AND ([EventType] = ?) AND ([Perso" & _

"nIndex] = ? OR ? IS NULL AND [PersonIndex] IS NULL)"

DeleteCmd.Connection = con

DeleteCmd.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))

DeleteCmd.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))

DeleteCmd.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))

DeleteCmd.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))

DeleteCmd.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))

tableEvents.Rows.RemoveAt(dgEvents.CurrentRowIndex)

daEvents.DeleteCommand = DeleteCmd

daEvents.Update(tableEvents)

Case "Add"



End Select

con.Close()
 
Rows does not have a delete method, so im not sure what method you refer to


Stephen Muecke said:
Terry,
The problem is with the line
tableEvents.Rows.RemoveAt(dgEvents.CurrentRowIndex)
RemoveAt completely removes a row from a collection and so there is nothing
to update
You should call the Delete method instead, which marks it for deletion.
Stephen

Terry Burns said:
This code is the contaxt menu handler assoc with a data grid, bound to
tableEvents and using daEvents adapter, the row deletes without error
message but does not delete at the access db, any ideas ??





Private Sub popUp_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim cc, sp As Point

Dim cmi As MenuItem

Dim TR As DataRow

Dim DT As DataTable

Dim DeleteCmd As New OleDbCommand

'open connection

con.Open()

cmi = DirectCast(sender, MenuItem)

Select Case cmi.Text

Case "Delete"

'Setup the Delete Command

DeleteCmd.CommandText = "DELETE FROM [Events] WHERE ([ID] = ?) AND ([Action]
= ?) AND ([EventType] = ?) AND ([Perso" & _

"nIndex] = ? OR ? IS NULL AND [PersonIndex] IS NULL)"

DeleteCmd.Connection = con

DeleteCmd.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))

DeleteCmd.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))

DeleteCmd.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))

DeleteCmd.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))

DeleteCmd.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))

tableEvents.Rows.RemoveAt(dgEvents.CurrentRowIndex)

daEvents.DeleteCommand = DeleteCmd

daEvents.Update(tableEvents)

Case "Add"



End Select

con.Close()
 
Back
Top