|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
data adapter update using datatable that has MANY changesI magine that I have a listbox that is bound to a data table. This means that there is the possiblity that the data table will have new rows, edited rows, and/or deleted rows. After everything is done, I would like, at the push of a button, to update the database with the change(s) made to the data table via the data adapter's update() method. However, when I call the update() method, I get an exception error telling me that the InsertCommand, UpdateCommand, or DeleteComand has not been set. My problem is, if I set the said properties, I do not have the necessary values to pass to the commands (e.g. values for new rows). How do I do this all at once? Thank you Darklight,
Probably you need (when your select is not too complex) only this http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdataoledboledbcommandbuilderclasstopic.asp It is there as well for SQL the only difference is that it than is named SQLcommandbuilder. I hope this helps? Cor Show quoteHide quote "Darklight" <Darkli***@discussions.microsoft.com> ... > Hi. > > I magine that I have a listbox that is bound to a data table. > This means that there is the possiblity that the data table will have > new rows, edited rows, and/or deleted rows. > > After everything is done, I would like, at the push of a button, to > update the database with the change(s) made to the data table > via the data adapter's update() method. > > However, when I call the update() method, I get an exception error > telling me that the InsertCommand, UpdateCommand, or DeleteComand > has not been set. > > My problem is, if I set the said properties, I do not have the necessary > values > to pass to the commands (e.g. values for new rows). > > How do I do this all at once? > > > Thank you thank you Cor, but I'm trying to avoid using this class as advised by most
references. Anyway, I have solved my problem regarding update() method in general now (I just had not correctly set the Insert and Delete commands with their respective parameter values and source column). I have a new problem now regarding the update command but I'll post that as another thread. Thanks again. Show quoteHide quote "Cor Ligthert" wrote: > Darklight, > > Probably you need (when your select is not too complex) only this > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdataoledboledbcommandbuilderclasstopic.asp > > It is there as well for SQL the only difference is that it than is named > SQLcommandbuilder. > > I hope this helps? > > Cor > > > "Darklight" <Darkli***@discussions.microsoft.com> > ... > > Hi. > > > > I magine that I have a listbox that is bound to a data table. > > This means that there is the possiblity that the data table will have > > new rows, edited rows, and/or deleted rows. > > > > After everything is done, I would like, at the push of a button, to > > update the database with the change(s) made to the data table > > via the data adapter's update() method. > > > > However, when I call the update() method, I get an exception error > > telling me that the InsertCommand, UpdateCommand, or DeleteComand > > has not been set. > > > > My problem is, if I set the said properties, I do not have the necessary > > values > > to pass to the commands (e.g. values for new rows). > > > > How do I do this all at once? > > > > > > Thank you > > > The Update() method will iterate over the new/modified/deleted DataRows,
copy values from the DataRow to the appropriate input parameters on the command, execute the appropriate insert/update/delete command, copy output parameter values back to the DataRow. the IDataParameter.SourceColumn property tells us for which column on the DataRow to push/pull the value. the IDataParameter.SourceVersion property tells us for modified rows, to use the original value or the new value, i.e original values go in the where clause and new values go in the set clause. You can also listen to the RowUpdating and RowUpdated events to see the command that will be executed. If you want, these are the times you can manually copy values between the DataRow and command. -Mark -- Show quoteHide quoteThis posting is provided "AS IS", with no warranties, and confers no rights. Please do not send email directly to this alias. This alias is for newsgroup purposes only. "Darklight" <Darkli***@discussions.microsoft.com> wrote in message news:637C1987-9F43-47C8-A1AF-74209DDC2149@microsoft.com... > Hi. > > I magine that I have a listbox that is bound to a data table. > This means that there is the possiblity that the data table will have > new rows, edited rows, and/or deleted rows. > > After everything is done, I would like, at the push of a button, to > update the database with the change(s) made to the data table > via the data adapter's update() method. > > However, when I call the update() method, I get an exception error > telling me that the InsertCommand, UpdateCommand, or DeleteComand > has not been set. > > My problem is, if I set the said properties, I do not have the necessary > values > to pass to the commands (e.g. values for new rows). > > How do I do this all at once? > > > Thank you
Other interesting topics
Removing rows from a DataTable is VERY slow
Specifying format of DateTime columns read from CSV files DataSet Memory Usage SQLDataReader Evaluating Reporting Tools for .NET Storing passwords in database Encrypting/Decrypting Connection String Problem copying datatable-long post populating dataset from excel range, error where no data. Can't import .OCX assembly into Web Matrix Project. |
|||||||||||||||||||||||