S
Sébastien
I generated my UpdateCommand with a CommandBuilder. As I seen on this group,
the CommandBuilder don't do the same the DataAdapter wizard do to generate
the UpdateCommand.
Here is my problem :
1- I add datas in my database table:
I add a new row in my DataSet then DataAdapter.Update(DataSet)
2- I update my database table :
I change a value in the row then DataAdapter.Update(DataSet)
It crash and it give me an error message saying I can't update 0 row. The
property HasError of my DataSet is set to true when that message is
displayed.
The problem don't happen if I have at least one row of data in the table I
try to update before I start the application. But if the table was empty
ebfore I execute my software, then it will crash for sure. It is a strange
problem.
To try to fix it, I created a OleDbDataAdapter using the wizard (so it add a
control on the form instead beeing a hardcoded object). I create a
DataAdapter object in my code also. I create my Insert and Delete commands
with the CommandBuilder for that coded obeject. For the UpdateCommand
property, I set it to the UpdateCommand property of my OleDbDataAdapter on
the form. I execute the software and now all work perfectly.
I don't want to use OleDbDataAdater on my form. Is there anything I don't do
right ?
Here is my actual way to get my dataadapter :
Private Function GetDataAdapter(ByVal strTable As String, ByVal
strConnection As String) As OleDb.OleDbDataAdapter
Dim oldOleDbCommandBuilder As OleDb.OleDbCommandBuilder
Dim oldOleDbDataAdapter As OleDb.OleDbDataAdapter
oldOleDbDataAdapter = New OleDb.OleDbDataAdapter("SELECT * FROM " &
strTable, strConnection)
oldOleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(oldOleDbDataAdapter)
oldOleDbDataAdapter.InsertCommand =
oldOleDbCommandBuilder.GetInsertCommand
oldOleDbDataAdapter.UpdateCommand =
oldOleDbCommandBuilder.GetUpdateCommand
oldOleDbDataAdapter.DeleteCommand =
oldOleDbCommandBuilder.GetDeleteCommand
Return oldOleDbDataAdapter
End Function
Is that OK or do I need to do something more ? I tryed to set the
UpdateCommandText manually, ut it still don't work. I tryed to copy the
exact same parameters the DataAdapter wizard give me and it did not work
either.
If someone could help me, I would appreciate.
Thank you.
the CommandBuilder don't do the same the DataAdapter wizard do to generate
the UpdateCommand.
Here is my problem :
1- I add datas in my database table:
I add a new row in my DataSet then DataAdapter.Update(DataSet)
2- I update my database table :
I change a value in the row then DataAdapter.Update(DataSet)
It crash and it give me an error message saying I can't update 0 row. The
property HasError of my DataSet is set to true when that message is
displayed.
The problem don't happen if I have at least one row of data in the table I
try to update before I start the application. But if the table was empty
ebfore I execute my software, then it will crash for sure. It is a strange
problem.
To try to fix it, I created a OleDbDataAdapter using the wizard (so it add a
control on the form instead beeing a hardcoded object). I create a
DataAdapter object in my code also. I create my Insert and Delete commands
with the CommandBuilder for that coded obeject. For the UpdateCommand
property, I set it to the UpdateCommand property of my OleDbDataAdapter on
the form. I execute the software and now all work perfectly.
I don't want to use OleDbDataAdater on my form. Is there anything I don't do
right ?
Here is my actual way to get my dataadapter :
Private Function GetDataAdapter(ByVal strTable As String, ByVal
strConnection As String) As OleDb.OleDbDataAdapter
Dim oldOleDbCommandBuilder As OleDb.OleDbCommandBuilder
Dim oldOleDbDataAdapter As OleDb.OleDbDataAdapter
oldOleDbDataAdapter = New OleDb.OleDbDataAdapter("SELECT * FROM " &
strTable, strConnection)
oldOleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(oldOleDbDataAdapter)
oldOleDbDataAdapter.InsertCommand =
oldOleDbCommandBuilder.GetInsertCommand
oldOleDbDataAdapter.UpdateCommand =
oldOleDbCommandBuilder.GetUpdateCommand
oldOleDbDataAdapter.DeleteCommand =
oldOleDbCommandBuilder.GetDeleteCommand
Return oldOleDbDataAdapter
End Function
Is that OK or do I need to do something more ? I tryed to set the
UpdateCommandText manually, ut it still don't work. I tryed to copy the
exact same parameters the DataAdapter wizard give me and it did not work
either.
If someone could help me, I would appreciate.
Thank you.