Home All Groups Group Topic Archive Search About

data adapter update using datatable that has MANY changes

Author
30 Nov 2004 10:39 AM
Darklight

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

Author
30 Nov 2004 10:56 AM
Cor Ligthert
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
Are all your drivers up to date? click for free checkup

Author
1 Dec 2004 9:45 AM
Darklight
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
>
>
>
Author
3 Dec 2004 9:04 PM
Mark Ashton
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

--
This 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.

Show quoteHide quote
"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

Bookmark and Share