Deleted rows wont delete

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()
 
S

Stephen Muecke

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
 
T

Terry Burns

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()
 
T

Terry Burns

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()
 

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