Home All Groups Group Topic Archive Search About

DataAdapter Update Does Nothing

Author
13 Apr 2005 2:18 PM
Demetri

I am attempting to insert a new row into the database. It is executing
without error but when I check the database there are no changes. Is there
some step I'm missing?

Here is my code:

OracleConnection con = new OracleConnection(this.MyConnectionString);

OracleDataAdapter da = new OracleDataAdapter();
da.SelectCommand = new OracleCommand("select * from " + this.DBOwner +
"MyTable where valid_status = 1 and MyTable_id = " + work.ID.ToString(),con);
OracleCommandBuilder cb = new OracleCommandBuilder(da);

DataSet ds = new DataSet();

da.Fill(ds, "MyTable");       

DataRow newRow = ds.Tables[0].NewRow();

newRow["xxxxxxx"] = work.property1;
newRow["xxxxxx"] = work.property2;
newRow["xxxxxxxxxx"] = work.property3;
newRow["xxxxx"] = work.property4;
newRow["xxxxx"] = work.property5;

ds.Tables[0].Rows.Add(newRow);

da.Update(ds,"MyTable");

--
-Demetri
Author
13 Apr 2005 2:42 PM
Sahil Malik [MVP]
Before the Update method, check and see if

a) Any of the RowStates are "Added". ( ds.Tables[0].Rows.Add(newRow); -->
Should take care of that I think).
b) DataAdapter.InsertCommand.CommandText is indeed what you expect.
c) BTW - Also you can trace the commands going to the DB - if the above two
fail, try and trace the command.

Your problem is within the above three. :)

- Sahil Malik [MVP]
http://codebetter.com/blogs/sahil.malik/



"Demetri" <Deme***@discussions.microsoft.com> wrote in message
news:4077EA24-7C4B-407C-9D12-CDF22534317E@microsoft.com...
> I am attempting to insert a new row into the database. It is executing
> without error but when I check the database there are no changes. Is there
> some step I'm missing?
>
> Here is my code:
>
> OracleConnection con = new OracleConnection(this.MyConnectionString);
>
> OracleDataAdapter da = new OracleDataAdapter();
> da.SelectCommand = new OracleCommand("select * from " + this.DBOwner +
> "MyTable where valid_status = 1 and MyTable_id = " +
work.ID.ToString(),con);
Show quoteHide quote
> OracleCommandBuilder cb = new OracleCommandBuilder(da);
>
> DataSet ds = new DataSet();
>
> da.Fill(ds, "MyTable");
>
> DataRow newRow = ds.Tables[0].NewRow();
>
> newRow["xxxxxxx"] = work.property1;
> newRow["xxxxxx"] = work.property2;
> newRow["xxxxxxxxxx"] = work.property3;
> newRow["xxxxx"] = work.property4;
> newRow["xxxxx"] = work.property5;
>
> ds.Tables[0].Rows.Add(newRow);
>
> da.Update(ds,"MyTable");
>
> --
> -Demetri
Are all your drivers up to date? click for free checkup

Author
13 Apr 2005 2:59 PM
Demetri
I put a breakpoint on the da.Update line of code and checked the
InsertCommand property of the dataAdapter in a watch window and low and
behold....look what the window showed:

da.InsertCommand    <undefined value>     System.Data.OracleClient.OracleCommand

Why isn't the command being built?

Show quoteHide quote
"Sahil Malik [MVP]" wrote:

> Before the Update method, check and see if
>
> a) Any of the RowStates are "Added". ( ds.Tables[0].Rows.Add(newRow); -->
> Should take care of that I think).
> b) DataAdapter.InsertCommand.CommandText is indeed what you expect.
> c) BTW - Also you can trace the commands going to the DB - if the above two
> fail, try and trace the command.
>
> Your problem is within the above three. :)
>
> - Sahil Malik [MVP]
> http://codebetter.com/blogs/sahil.malik/
>
>
>
> "Demetri" <Deme***@discussions.microsoft.com> wrote in message
> news:4077EA24-7C4B-407C-9D12-CDF22534317E@microsoft.com...
> > I am attempting to insert a new row into the database. It is executing
> > without error but when I check the database there are no changes. Is there
> > some step I'm missing?
> >
> > Here is my code:
> >
> > OracleConnection con = new OracleConnection(this.MyConnectionString);
> >
> > OracleDataAdapter da = new OracleDataAdapter();
> > da.SelectCommand = new OracleCommand("select * from " + this.DBOwner +
> > "MyTable where valid_status = 1 and MyTable_id = " +
> work.ID.ToString(),con);
> > OracleCommandBuilder cb = new OracleCommandBuilder(da);
> >
> > DataSet ds = new DataSet();
> >
> > da.Fill(ds, "MyTable");
> >
> > DataRow newRow = ds.Tables[0].NewRow();
> >
> > newRow["xxxxxxx"] = work.property1;
> > newRow["xxxxxx"] = work.property2;
> > newRow["xxxxxxxxxx"] = work.property3;
> > newRow["xxxxx"] = work.property4;
> > newRow["xxxxx"] = work.property5;
> >
> > ds.Tables[0].Rows.Add(newRow);
> >
> > da.Update(ds,"MyTable");
> >
> > --
> > -Demetri
>
>
>
Author
13 Apr 2005 3:27 PM
Sahil Malik [MVP]
Okay so now that we zeroed in on the reason. :)

Better not rely on the autobuilding of the command. Better specify your own.

- Sahil Malik [MVP]
http://codebetter.com/blogs/sahil.malik/



"Demetri" <Deme***@discussions.microsoft.com> wrote in message
news:FC969587-FE1A-448D-80EE-ED2513342C98@microsoft.com...
> I put a breakpoint on the da.Update line of code and checked the
> InsertCommand property of the dataAdapter in a watch window and low and
> behold....look what the window showed:
>
> da.InsertCommand <undefined value>
System.Data.OracleClient.OracleCommand
>
> Why isn't the command being built?
>
> "Sahil Malik [MVP]" wrote:
>
> > Before the Update method, check and see if
> >
> > a) Any of the RowStates are "Added". (
ds.Tables[0].Rows.Add(newRow); -->
Show quoteHide quote
> > Should take care of that I think).
> > b) DataAdapter.InsertCommand.CommandText is indeed what you expect.
> > c) BTW - Also you can trace the commands going to the DB - if the above
two
> > fail, try and trace the command.
> >
> > Your problem is within the above three. :)
> >
> > - Sahil Malik [MVP]
> > http://codebetter.com/blogs/sahil.malik/
> >
> >
> >
> > "Demetri" <Deme***@discussions.microsoft.com> wrote in message
> > news:4077EA24-7C4B-407C-9D12-CDF22534317E@microsoft.com...
> > > I am attempting to insert a new row into the database. It is executing
> > > without error but when I check the database there are no changes. Is
there
> > > some step I'm missing?
> > >
> > > Here is my code:
> > >
> > > OracleConnection con = new OracleConnection(this.MyConnectionString);
> > >
> > > OracleDataAdapter da = new OracleDataAdapter();
> > > da.SelectCommand = new OracleCommand("select * from " + this.DBOwner +
> > > "MyTable where valid_status = 1 and MyTable_id = " +
> > work.ID.ToString(),con);
> > > OracleCommandBuilder cb = new OracleCommandBuilder(da);
> > >
> > > DataSet ds = new DataSet();
> > >
> > > da.Fill(ds, "MyTable");
> > >
> > > DataRow newRow = ds.Tables[0].NewRow();
> > >
> > > newRow["xxxxxxx"] = work.property1;
> > > newRow["xxxxxx"] = work.property2;
> > > newRow["xxxxxxxxxx"] = work.property3;
> > > newRow["xxxxx"] = work.property4;
> > > newRow["xxxxx"] = work.property5;
> > >
> > > ds.Tables[0].Rows.Add(newRow);
> > >
> > > da.Update(ds,"MyTable");
> > >
> > > --
> > > -Demetri
> >
> >
> >
Author
13 Apr 2005 5:13 PM
Marina
That is because it is getting its value from the commandbuilder.  This is
the way it is supposed to be.

Show quoteHide quote
"Demetri" <Deme***@discussions.microsoft.com> wrote in message
news:FC969587-FE1A-448D-80EE-ED2513342C98@microsoft.com...
>I put a breakpoint on the da.Update line of code and checked the
> InsertCommand property of the dataAdapter in a watch window and low and
> behold....look what the window showed:
>
> da.InsertCommand <undefined value>
> System.Data.OracleClient.OracleCommand
>
> Why isn't the command being built?
>
> "Sahil Malik [MVP]" wrote:
>
>> Before the Update method, check and see if
>>
>> a) Any of the RowStates are "Added". ( ds.Tables[0].Rows.Add(newRow); -->
>> Should take care of that I think).
>> b) DataAdapter.InsertCommand.CommandText is indeed what you expect.
>> c) BTW - Also you can trace the commands going to the DB - if the above
>> two
>> fail, try and trace the command.
>>
>> Your problem is within the above three. :)
>>
>> - Sahil Malik [MVP]
>> http://codebetter.com/blogs/sahil.malik/
>>
>>
>>
>> "Demetri" <Deme***@discussions.microsoft.com> wrote in message
>> news:4077EA24-7C4B-407C-9D12-CDF22534317E@microsoft.com...
>> > I am attempting to insert a new row into the database. It is executing
>> > without error but when I check the database there are no changes. Is
>> > there
>> > some step I'm missing?
>> >
>> > Here is my code:
>> >
>> > OracleConnection con = new OracleConnection(this.MyConnectionString);
>> >
>> > OracleDataAdapter da = new OracleDataAdapter();
>> > da.SelectCommand = new OracleCommand("select * from " + this.DBOwner +
>> > "MyTable where valid_status = 1 and MyTable_id = " +
>> work.ID.ToString(),con);
>> > OracleCommandBuilder cb = new OracleCommandBuilder(da);
>> >
>> > DataSet ds = new DataSet();
>> >
>> > da.Fill(ds, "MyTable");
>> >
>> > DataRow newRow = ds.Tables[0].NewRow();
>> >
>> > newRow["xxxxxxx"] = work.property1;
>> > newRow["xxxxxx"] = work.property2;
>> > newRow["xxxxxxxxxx"] = work.property3;
>> > newRow["xxxxx"] = work.property4;
>> > newRow["xxxxx"] = work.property5;
>> >
>> > ds.Tables[0].Rows.Add(newRow);
>> >
>> > da.Update(ds,"MyTable");
>> >
>> > --
>> > -Demetri
>>
>>
>>
Author
13 Apr 2005 3:36 PM
W.G. Ryan eMVP
I"m chiming in late but Sahil's my homie so I think he'll let it go.
Anyway, noticed you were using a commandbuilder- do you have  a key on the
table?  No key equals Yuck, in general, and when using anything that
autogenerates commands in particular.

A good test is to try to drag a dataadapter and see if you can configure
it - if all the commands are generated. If they aren't, then you can be sure
that your commandbuilder stuff is going to cause you some drama.

Cheers,

Bill

"Demetri" <Deme***@discussions.microsoft.com> wrote in message
news:4077EA24-7C4B-407C-9D12-CDF22534317E@microsoft.com...
> I am attempting to insert a new row into the database. It is executing
> without error but when I check the database there are no changes. Is there
> some step I'm missing?
>
> Here is my code:
>
> OracleConnection con = new OracleConnection(this.MyConnectionString);
>
> OracleDataAdapter da = new OracleDataAdapter();
> da.SelectCommand = new OracleCommand("select * from " + this.DBOwner +
> "MyTable where valid_status = 1 and MyTable_id = " +
work.ID.ToString(),con);
Show quoteHide quote
> OracleCommandBuilder cb = new OracleCommandBuilder(da);
>
> DataSet ds = new DataSet();
>
> da.Fill(ds, "MyTable");
>
> DataRow newRow = ds.Tables[0].NewRow();
>
> newRow["xxxxxxx"] = work.property1;
> newRow["xxxxxx"] = work.property2;
> newRow["xxxxxxxxxx"] = work.property3;
> newRow["xxxxx"] = work.property4;
> newRow["xxxxx"] = work.property5;
>
> ds.Tables[0].Rows.Add(newRow);
>
> da.Update(ds,"MyTable");
>
> --
> -Demetri
Author
13 Apr 2005 3:44 PM
Sahil Malik [MVP]
Hey dude,

Thats a good answer. I shudda mentioned that muhself !! :)

But either way, I'm not too big a fan of CommandBuilder - atleast not in
1.1. In 2.0 it has enhancements that let you specify the ConflictDetection
methodology, so the command generated isn't so ugly.

With Oracle though, if you really wanted to detect conflicts reliably, you'd
have no choice but to check for all columns (CommandBuilder's default
option) - and that is hella inefficient.

- Sahil Malik [MVP]
http://codebetter.com/blogs/sahil.malik/



Show quoteHide quote
"W.G. Ryan eMVP" <WilliamR***@gmail.com> wrote in message
news:udA9f6DQFHA.1528@TK2MSFTNGP09.phx.gbl...
> I"m chiming in late but Sahil's my homie so I think he'll let it go.
> Anyway, noticed you were using a commandbuilder- do you have  a key on the
> table?  No key equals Yuck, in general, and when using anything that
> autogenerates commands in particular.
>
> A good test is to try to drag a dataadapter and see if you can configure
> it - if all the commands are generated. If they aren't, then you can be
sure
> that your commandbuilder stuff is going to cause you some drama.
>
> Cheers,
>
> Bill
>
> --
> W.G. Ryan, MVP
>
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> "Demetri" <Deme***@discussions.microsoft.com> wrote in message
> news:4077EA24-7C4B-407C-9D12-CDF22534317E@microsoft.com...
> > I am attempting to insert a new row into the database. It is executing
> > without error but when I check the database there are no changes. Is
there
> > some step I'm missing?
> >
> > Here is my code:
> >
> > OracleConnection con = new OracleConnection(this.MyConnectionString);
> >
> > OracleDataAdapter da = new OracleDataAdapter();
> > da.SelectCommand = new OracleCommand("select * from " + this.DBOwner +
> > "MyTable where valid_status = 1 and MyTable_id = " +
> work.ID.ToString(),con);
> > OracleCommandBuilder cb = new OracleCommandBuilder(da);
> >
> > DataSet ds = new DataSet();
> >
> > da.Fill(ds, "MyTable");
> >
> > DataRow newRow = ds.Tables[0].NewRow();
> >
> > newRow["xxxxxxx"] = work.property1;
> > newRow["xxxxxx"] = work.property2;
> > newRow["xxxxxxxxxx"] = work.property3;
> > newRow["xxxxx"] = work.property4;
> > newRow["xxxxx"] = work.property5;
> >
> > ds.Tables[0].Rows.Add(newRow);
> >
> > da.Update(ds,"MyTable");
> >
> > --
> > -Demetri
>
>
Author
13 Apr 2005 4:40 PM
John Papa
I agree, CommandBuilder is generally not a good idea. You can almost always
create SQL that is more efficient on your own. However, I have seen it be
useful to create the SQL and then copy and paste it into your own SQL
statement. In other words, use the CommmandBuilder just to get you started
with your SQL statement.

Anyway, these fine gentlemen have already chimed in with very good comments
so I will be quiet now ;-)

-- John Papa

Show quoteHide quote
"Sahil Malik [MVP]" wrote:

> Hey dude,
>
> Thats a good answer. I shudda mentioned that muhself !! :)
>
> But either way, I'm not too big a fan of CommandBuilder - atleast not in
> 1.1. In 2.0 it has enhancements that let you specify the ConflictDetection
> methodology, so the command generated isn't so ugly.
>
> With Oracle though, if you really wanted to detect conflicts reliably, you'd
> have no choice but to check for all columns (CommandBuilder's default
> option) - and that is hella inefficient.
>
> - Sahil Malik [MVP]
> http://codebetter.com/blogs/sahil.malik/
>
>
>
> "W.G. Ryan eMVP" <WilliamR***@gmail.com> wrote in message
> news:udA9f6DQFHA.1528@TK2MSFTNGP09.phx.gbl...
> > I"m chiming in late but Sahil's my homie so I think he'll let it go.
> > Anyway, noticed you were using a commandbuilder- do you have  a key on the
> > table?  No key equals Yuck, in general, and when using anything that
> > autogenerates commands in particular.
> >
> > A good test is to try to drag a dataadapter and see if you can configure
> > it - if all the commands are generated. If they aren't, then you can be
> sure
> > that your commandbuilder stuff is going to cause you some drama.
> >
> > Cheers,
> >
> > Bill
> >
> > --
> > W.G. Ryan, MVP
> >
> > www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> > "Demetri" <Deme***@discussions.microsoft.com> wrote in message
> > news:4077EA24-7C4B-407C-9D12-CDF22534317E@microsoft.com...
> > > I am attempting to insert a new row into the database. It is executing
> > > without error but when I check the database there are no changes. Is
> there
> > > some step I'm missing?
> > >
> > > Here is my code:
> > >
> > > OracleConnection con = new OracleConnection(this.MyConnectionString);
> > >
> > > OracleDataAdapter da = new OracleDataAdapter();
> > > da.SelectCommand = new OracleCommand("select * from " + this.DBOwner +
> > > "MyTable where valid_status = 1 and MyTable_id = " +
> > work.ID.ToString(),con);
> > > OracleCommandBuilder cb = new OracleCommandBuilder(da);
> > >
> > > DataSet ds = new DataSet();
> > >
> > > da.Fill(ds, "MyTable");
> > >
> > > DataRow newRow = ds.Tables[0].NewRow();
> > >
> > > newRow["xxxxxxx"] = work.property1;
> > > newRow["xxxxxx"] = work.property2;
> > > newRow["xxxxxxxxxx"] = work.property3;
> > > newRow["xxxxx"] = work.property4;
> > > newRow["xxxxx"] = work.property5;
> > >
> > > ds.Tables[0].Rows.Add(newRow);
> > >
> > > da.Update(ds,"MyTable");
> > >
> > > --
> > > -Demetri
> >
> >
>
>
>

Bookmark and Share