Ennio
asked on
DataGridview Delete and update.
I got my datagridview to work, I now can query the DB, and insert data to it. Now I need to know how can I delete and update a datagridview.
If I select on the side the row, and press delete how can I remove it from the DB?
also if I make some changes on the datagridview fields how can I update the DB?
If I select on the side the row, and press delete how can I remove it from the DB?
also if I make some changes on the datagridview fields how can I update the DB?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I fixed the SQL statement I the data was not removed from the DB
here is the error msg
A first chance exception of type 'System.Data.OleDb.OleDbEx ception' occurred in System.Data.dll
System.Data.OleDb.OleDbExc eption: Syntax error (missing operator) in query expression 'tbl_agenda where id = 1'.
at System.Data.Common.DbDataA dapter.Upd atedRowSta tusErrors( RowUpdated EventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataA dapter.Upd atedRowSta tus(RowUpd atedEventA rgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataA dapter.Upd ate(DataRo w[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataA dapter.Upd ateFromDat aTable(Dat aTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataA dapter.Upd ate(DataSe t dataSet, String srcTable)
at System.Data.Common.DbDataA dapter.Upd ate(DataSe t dataSet)
at Agenda.data.deleteData(Int 32 number) in C:\Documents and Settings\Ennio\My Documents\Visual Studio 2005\Projects\Agenda\Agend a\data.vb: line 58
here is the error msg
A first chance exception of type 'System.Data.OleDb.OleDbEx
System.Data.OleDb.OleDbExc
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at Agenda.data.deleteData(Int
ASKER
got it to work... missed the E on the delete and the FROM
:)
:)
Hi
And glad you got it
Here delete from the database
cmdDelete.CommandText = "DELET tbl_agenda where id = " & myDataSet.Tables("tbl_agen da").Rows( number).It em(0)
cmdDelete.Connection = myConn
myAdapter.DeleteCommand = cmdDelete
then delete from the dataset ! THAT just is ok
myDataSet.Tables("tbl_agen da").Rows( number).De lete()
Then you Delete one more time the same record in the database
myAdapter.Update(myDataSet )
Your myAdapter has -----insert update delete and select statements implicit + all the connection data ,
so you dont even have to write con.open and con.close---just myAdapter.Update(myDataSet )
then you dont need this code
cmdDelete.CommandText = "DELET tbl_agenda where id = " & myDataSet.Tables("tbl_agen da").Rows( number).It em(0)
cmdDelete.Connection = myConn
myAdapter.DeleteCommand = cmdDelete
try only this
Public Sub deleteData(ByVal number As Integer)
Dim cb As New OleDb.OleDbCommandBuilder( myAdapter)
Try
myDataSet.Tables("tbl_agen da").Rows( number).De lete()
myAdapter.Update(myDataSet )
Catch ex As Exception
Debug.Write(ex.ToString)
End Try
End Sub
vbturbo
And glad you got it
Here delete from the database
cmdDelete.CommandText = "DELET tbl_agenda where id = " & myDataSet.Tables("tbl_agen
cmdDelete.Connection = myConn
myAdapter.DeleteCommand = cmdDelete
then delete from the dataset ! THAT just is ok
myDataSet.Tables("tbl_agen
Then you Delete one more time the same record in the database
myAdapter.Update(myDataSet
Your myAdapter has -----insert update delete and select statements implicit + all the connection data ,
so you dont even have to write con.open and con.close---just myAdapter.Update(myDataSet
then you dont need this code
cmdDelete.CommandText = "DELET tbl_agenda where id = " & myDataSet.Tables("tbl_agen
cmdDelete.Connection = myConn
myAdapter.DeleteCommand = cmdDelete
try only this
Public Sub deleteData(ByVal number As Integer)
Dim cb As New OleDb.OleDbCommandBuilder(
Try
myDataSet.Tables("tbl_agen
myAdapter.Update(myDataSet
Catch ex As Exception
Debug.Write(ex.ToString)
End Try
End Sub
vbturbo
will have the same effect
ASKER
Here is the error code
A first chance exception of type 'System.Data.OleDb.OleDbEx
System.Data.OleDb.OleDbExc
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at Agenda.data.deleteData(Int
here is my code:
Public Sub deleteData(ByVal number As Integer)
Try
cmdDelete.CommandText = "DELET tbl_agenda where id = " & myDataSet.Tables("tbl_agen
cmdDelete.Connection = myConn
myAdapter.DeleteCommand = cmdDelete
myDataSet.Tables("tbl_agen
myAdapter.Update(myDataSet
Catch ex As Exception
Debug.Write(ex.ToString)
End Try
End Sub