PC Review


Reply
Thread Tools Rate Thread

DataAdapter.Update is not working

 
 
Ashish Sheth
Guest
Posts: n/a
 
      14th Sep 2004
Hi Gurus,

I am using OleDBDataAdapter to update the data in the DB2. I am only taking
the Modified Data in a Datatable using Datatable.GetChanges() method and
passing the modified data to the DataAdapter's Update method. I am
specifying the UpdateCommand for the Dataadapter by my own.
All is fine when I execute the DataAdapter.Update statement, it is not
giving me any error.. but when I check the database for the modified value,
the database is not getting updated.
Also when I checked the 'RecordsAffected' property of the UpdateCommand
after calling the DataAdapter.Update method it is always returning -1. Why?
Please help me as soon as possible.

thanks and regards,
Ashish Sheth


 
Reply With Quote
 
 
 
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      14th Sep 2004
Hi,

You might check adapter's RowUpdating/Updated events too see what's going
on.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Ashish Sheth" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Gurus,
>
> I am using OleDBDataAdapter to update the data in the DB2. I am only
> taking
> the Modified Data in a Datatable using Datatable.GetChanges() method and
> passing the modified data to the DataAdapter's Update method. I am
> specifying the UpdateCommand for the Dataadapter by my own.
> All is fine when I execute the DataAdapter.Update statement, it is not
> giving me any error.. but when I check the database for the modified
> value,
> the database is not getting updated.
> Also when I checked the 'RecordsAffected' property of the UpdateCommand
> after calling the DataAdapter.Update method it is always returning -1.
> Why?
> Please help me as soon as possible.
>
> thanks and regards,
> Ashish Sheth
>
>



 
Reply With Quote
 
Ashish Sheth
Guest
Posts: n/a
 
      14th Sep 2004
Thanks Miha,

But as I mentioned, although dataadapter.Update method is executed it is not
updating the row in the Database and the RowUpdated event is also not
firing. So I am not able to find out what might be the problem. I am facing
this problem since last so many days... I check out the query and all the
parameters which I am passing... everything is fine... So can you tell me
what exactly is the problem?

thanks and regards,
Ashish
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> You might check adapter's RowUpdating/Updated events too see what's going
> on.
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> miha at rthand com
> www.rthand.com
>
> "Ashish Sheth" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi Gurus,
> >
> > I am using OleDBDataAdapter to update the data in the DB2. I am only
> > taking
> > the Modified Data in a Datatable using Datatable.GetChanges() method and
> > passing the modified data to the DataAdapter's Update method. I am
> > specifying the UpdateCommand for the Dataadapter by my own.
> > All is fine when I execute the DataAdapter.Update statement, it is not
> > giving me any error.. but when I check the database for the modified
> > value,
> > the database is not getting updated.
> > Also when I checked the 'RecordsAffected' property of the UpdateCommand
> > after calling the DataAdapter.Update method it is always returning -1.
> > Why?
> > Please help me as soon as possible.
> >
> > thanks and regards,
> > Ashish Sheth
> >
> >

>
>



 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      14th Sep 2004
Do you have some sql profiler utility (that lets you see what's going on)?
Are you sure that GetChanges() returns rows?
Are you sure that the rows are marked as modified only?
Do you Commit the transaction?

There can be many reasons...

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Ashish Sheth" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Thanks Miha,
>
> But as I mentioned, although dataadapter.Update method is executed it is
> not
> updating the row in the Database and the RowUpdated event is also not
> firing. So I am not able to find out what might be the problem. I am
> facing
> this problem since last so many days... I check out the query and all the
> parameters which I am passing... everything is fine... So can you tell me
> what exactly is the problem?
>
> thanks and regards,
> Ashish
> "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>>
>> You might check adapter's RowUpdating/Updated events too see what's going
>> on.
>>
>> --
>> Miha Markic [MVP C#] - RightHand .NET consulting & development
>> miha at rthand com
>> www.rthand.com
>>
>> "Ashish Sheth" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Hi Gurus,
>> >
>> > I am using OleDBDataAdapter to update the data in the DB2. I am only
>> > taking
>> > the Modified Data in a Datatable using Datatable.GetChanges() method
>> > and
>> > passing the modified data to the DataAdapter's Update method. I am
>> > specifying the UpdateCommand for the Dataadapter by my own.
>> > All is fine when I execute the DataAdapter.Update statement, it is not
>> > giving me any error.. but when I check the database for the modified
>> > value,
>> > the database is not getting updated.
>> > Also when I checked the 'RecordsAffected' property of the UpdateCommand
>> > after calling the DataAdapter.Update method it is always returning -1.
>> > Why?
>> > Please help me as soon as possible.
>> >
>> > thanks and regards,
>> > Ashish Sheth
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
Ashish Sheth
Guest
Posts: n/a
 
      14th Sep 2004
Ya, I am checking all this thing... Actually I am inserting a row in the
Datatable, so GetChanges method is returning me the Datatable with the newly
inserted rows with RowState as Added. and I am specifying my own
InsertCommand. After calling the dataAdapter.Update method I am commiting
the transaction also.
But when in the debug mode after executing the dataAdapter.Update method
when I see the dataAdapter.RecordsAffected property in the Watch window it
is showing -1. and after the transaction is commited when I see the Database
table the row is not inserted. I don't understand what is going wrong here.


thanks and regards,
Ashish Sheth

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:O%(E-Mail Removed)...
> Do you have some sql profiler utility (that lets you see what's going on)?
> Are you sure that GetChanges() returns rows?
> Are you sure that the rows are marked as modified only?
> Do you Commit the transaction?
>
> There can be many reasons...
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> miha at rthand com
> www.rthand.com
>
> "Ashish Sheth" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Thanks Miha,
> >
> > But as I mentioned, although dataadapter.Update method is executed it is
> > not
> > updating the row in the Database and the RowUpdated event is also not
> > firing. So I am not able to find out what might be the problem. I am
> > facing
> > this problem since last so many days... I check out the query and all

the
> > parameters which I am passing... everything is fine... So can you tell

me
> > what exactly is the problem?
> >
> > thanks and regards,
> > Ashish
> > "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
> > news:(E-Mail Removed)...
> >> Hi,
> >>
> >> You might check adapter's RowUpdating/Updated events too see what's

going
> >> on.
> >>
> >> --
> >> Miha Markic [MVP C#] - RightHand .NET consulting & development
> >> miha at rthand com
> >> www.rthand.com
> >>
> >> "Ashish Sheth" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> > Hi Gurus,
> >> >
> >> > I am using OleDBDataAdapter to update the data in the DB2. I am only
> >> > taking
> >> > the Modified Data in a Datatable using Datatable.GetChanges() method
> >> > and
> >> > passing the modified data to the DataAdapter's Update method. I am
> >> > specifying the UpdateCommand for the Dataadapter by my own.
> >> > All is fine when I execute the DataAdapter.Update statement, it is

not
> >> > giving me any error.. but when I check the database for the modified
> >> > value,
> >> > the database is not getting updated.
> >> > Also when I checked the 'RecordsAffected' property of the

UpdateCommand
> >> > after calling the DataAdapter.Update method it is always

returning -1.
> >> > Why?
> >> > Please help me as soon as possible.
> >> >
> >> > thanks and regards,
> >> > Ashish Sheth
> >> >
> >> >
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      14th Sep 2004

"Ashish Sheth" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Ya, I am checking all this thing... Actually I am inserting a row in the
> Datatable, so GetChanges method is returning me the Datatable with the
> newly
> inserted rows with RowState as Added. and I am specifying my own
> InsertCommand. After calling the dataAdapter.Update method I am commiting
> the transaction also.
> But when in the debug mode after executing the dataAdapter.Update method
> when I see the dataAdapter.RecordsAffected property in the Watch window
> it
> is showing -1. and after the transaction is commited when I see the
> Database
> table the row is not inserted. I don't understand what is going wrong
> here.
>

You mean e.RecordsAffected in the RowUpdated event?
What happens if you manually invoke your InsertCommand with some parameter
values?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com


 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      14th Sep 2004
Hard to say.
First, you don't need to invoke Copy() on GetChanges.
Next, assign GetChanges to a datatable prior to invoking Update and check
out the table content if there are rows as expected.
Next, implement RowUpdating and RowUpdated events what they say.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Ashish Sheth" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi Miha,
>
> In my case due to program logic I can't directly execute the InsertCommand
> manually. Please find the attached file for the source code. I have
> modified
> the code for your understanding but this is what exactly I am doing in my
> application. Here Now I am facing anonther problem.. the recordsAffected
> is
> now 1 instead of -1... but still it is not updating in the Database... I
> don't know what's wrong in this code.. please reply as soon as possible.
>
> thanks and regards,
> Ashish Sheth
>
> "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
> news:(E-Mail Removed)...
>>
>> "Ashish Sheth" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Ya, I am checking all this thing... Actually I am inserting a row in
>> > the
>> > Datatable, so GetChanges method is returning me the Datatable with the
>> > newly
>> > inserted rows with RowState as Added. and I am specifying my own
>> > InsertCommand. After calling the dataAdapter.Update method I am

> commiting
>> > the transaction also.
>> > But when in the debug mode after executing the dataAdapter.Update
>> > method
>> > when I see the dataAdapter.RecordsAffected property in the Watch
>> > window
>> > it
>> > is showing -1. and after the transaction is commited when I see the
>> > Database
>> > table the row is not inserted. I don't understand what is going wrong
>> > here.
>> >

>> You mean e.RecordsAffected in the RowUpdated event?
>> What happens if you manually invoke your InsertCommand with some
>> parameter
>> values?
>>
>> --
>> Miha Markic [MVP C#] - RightHand .NET consulting & development
>> miha at rthand com
>> www.rthand.com
>>
>>

>
>
>



 
Reply With Quote
 
Ashish Sheth
Guest
Posts: n/a
 
      15th Sep 2004
thanks Miha,
I did what u said... but still it is not working... and I got some strange
result also...
First I am not using the Copy() function(but in actual application I need to
do that) and also I am calling the GetChanges() method before calling the
Update() method on DataAdapter. GetChanges() returns the rows as expected.
So Update method should actually update the row in the database.

I also implemented the RowUpdating and RowUpdated event handler and in that
I am getting the Row which I inserted... but
In the RowUpdated event when I check the e.RecordsAffected property, it
is -1, while the DataAdapter.Update method returns 1. I have gone through
whole MSDN documentation and I don't think I am missing anything, but still
something is wrong. Please tell me what is going wrong here..


thanks and regards,
Ashish Sheth


"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:O$(E-Mail Removed)...
> Hard to say.
> First, you don't need to invoke Copy() on GetChanges.
> Next, assign GetChanges to a datatable prior to invoking Update and check
> out the table content if there are rows as expected.
> Next, implement RowUpdating and RowUpdated events what they say.
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> miha at rthand com
> www.rthand.com
>
> "Ashish Sheth" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Hi Miha,
> >
> > In my case due to program logic I can't directly execute the

InsertCommand
> > manually. Please find the attached file for the source code. I have
> > modified
> > the code for your understanding but this is what exactly I am doing in

my
> > application. Here Now I am facing anonther problem.. the recordsAffected
> > is
> > now 1 instead of -1... but still it is not updating in the Database... I
> > don't know what's wrong in this code.. please reply as soon as possible.
> >
> > thanks and regards,
> > Ashish Sheth
> >
> > "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
> > news:(E-Mail Removed)...
> >>
> >> "Ashish Sheth" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> > Ya, I am checking all this thing... Actually I am inserting a row in
> >> > the
> >> > Datatable, so GetChanges method is returning me the Datatable with

the
> >> > newly
> >> > inserted rows with RowState as Added. and I am specifying my own
> >> > InsertCommand. After calling the dataAdapter.Update method I am

> > commiting
> >> > the transaction also.
> >> > But when in the debug mode after executing the dataAdapter.Update
> >> > method
> >> > when I see the dataAdapter.RecordsAffected property in the Watch
> >> > window
> >> > it
> >> > is showing -1. and after the transaction is commited when I see the
> >> > Database
> >> > table the row is not inserted. I don't understand what is going wrong
> >> > here.
> >> >
> >> You mean e.RecordsAffected in the RowUpdated event?
> >> What happens if you manually invoke your InsertCommand with some
> >> parameter
> >> values?
> >>
> >> --
> >> Miha Markic [MVP C#] - RightHand .NET consulting & development
> >> miha at rthand com
> >> www.rthand.com
> >>
> >>

> >
> >
> >

>
>



 
Reply With Quote
 
Ashish Sheth
Guest
Posts: n/a
 
      15th Sep 2004
Sorry Miha,
I found the problem. Actually I am specifying alias name in all the columns
i am fetching... while inserting the rows for one column I have given a
wrong alias name and because of that DataAdapter.Update method was not
updating and it was not throwing any error(I believe that atleast it should
throw any error, if I specify any wrong alias name!!)

any way,
thanks
Ashish
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:O$(E-Mail Removed)...
> Hard to say.
> First, you don't need to invoke Copy() on GetChanges.
> Next, assign GetChanges to a datatable prior to invoking Update and check
> out the table content if there are rows as expected.
> Next, implement RowUpdating and RowUpdated events what they say.
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> miha at rthand com
> www.rthand.com
>
> "Ashish Sheth" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Hi Miha,
> >
> > In my case due to program logic I can't directly execute the

InsertCommand
> > manually. Please find the attached file for the source code. I have
> > modified
> > the code for your understanding but this is what exactly I am doing in

my
> > application. Here Now I am facing anonther problem.. the recordsAffected
> > is
> > now 1 instead of -1... but still it is not updating in the Database... I
> > don't know what's wrong in this code.. please reply as soon as possible.
> >
> > thanks and regards,
> > Ashish Sheth
> >
> > "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
> > news:(E-Mail Removed)...
> >>
> >> "Ashish Sheth" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> > Ya, I am checking all this thing... Actually I am inserting a row in
> >> > the
> >> > Datatable, so GetChanges method is returning me the Datatable with

the
> >> > newly
> >> > inserted rows with RowState as Added. and I am specifying my own
> >> > InsertCommand. After calling the dataAdapter.Update method I am

> > commiting
> >> > the transaction also.
> >> > But when in the debug mode after executing the dataAdapter.Update
> >> > method
> >> > when I see the dataAdapter.RecordsAffected property in the Watch
> >> > window
> >> > it
> >> > is showing -1. and after the transaction is commited when I see the
> >> > Database
> >> > table the row is not inserted. I don't understand what is going wrong
> >> > here.
> >> >
> >> You mean e.RecordsAffected in the RowUpdated event?
> >> What happens if you manually invoke your InsertCommand with some
> >> parameter
> >> values?
> >>
> >> --
> >> Miha Markic [MVP C#] - RightHand .NET consulting & development
> >> miha at rthand com
> >> www.rthand.com
> >>
> >>

> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dataadapter.Update() multiple table update strategies jarb Microsoft ADO .NET 3 2nd Nov 2006 08:57 AM
DataAdapter.Update not working Craig Hoy Microsoft ADO .NET 4 9th Feb 2006 02:20 AM
How best to update DataAdapter to make DataGrid update immediately like table in Access would John Edens Microsoft Dot NET Framework Forms 1 5th Aug 2005 07:44 AM
DataAdapter.Update Command Failed To Update Database Chris Lee Microsoft ADO .NET 10 4th Aug 2004 06:53 PM
DataAdapter update - not working Shahar Microsoft C# .NET 1 10th Aug 2003 03:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:30 AM.