DataAdapter.Update is not working

A

Ashish Sheth

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
 
M

Miha Markic [MVP C#]

Hi,

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

Ashish Sheth

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 said:
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 said:
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
 
M

Miha Markic [MVP C#]

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 said:
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 said:
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 said:
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
 
A

Ashish Sheth

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 said:
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 said:
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 said:
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

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
 
M

Miha Markic [MVP C#]

Ashish Sheth said:
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?
 
M

Miha Markic [MVP C#]

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

Ashish Sheth

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 said:
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 said:
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
 
A

Ashish Sheth

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 said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top