Home All Groups Group Topic Archive Search About

DataAdapter call ExecuteReader instead of ExecuteNonQuery

Author
31 Dec 2004 8:37 AM
Lionel LASKE
I'm working on my own implementation of an ADO.NET Data Provider
derived from IDbXXXX classes and MSDN sample
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconImplementingNETDataProvider.asp).
All is fine when I execute simple Command and DataReader but I got an
error with DataAdapter.
Running of SelectCmd and InsertCmd work fine but each UpdateCmd or
DeleteCmd thrown a DBConcurrencyException.
It seems that problem is that DataAdapter call ExecuteReader instead
of ExecuteNonQuery on InsertCmd, UpdateCmd and DeleteCmd. So, number
of row affected is probably incorrect.
Do I miss something or is it an usual way of working for a DataAdapter
?
Why ExecuteReader is called for an Update and a Delete without any
result expected ?
Thanks in advance for your help or advices.

               Lionel.

Author
31 Dec 2004 8:55 AM
Miha Markic [MVP C#]
Hi Lionel,

I guess the reader part is because of concurrency issues (to load timestamp
or autoinc key).
See help on
IDbCommand.UpdatedRowSource Property

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Show quote
"Lionel LASKE" <lla***@c2s.fr> wrote in message
news:dfc3550a.0412310037.5509c913@posting.google.com...
> I'm working on my own implementation of an ADO.NET Data Provider
> derived from IDbXXXX classes and MSDN sample
> (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconImplementingNETDataProvider.asp).
> All is fine when I execute simple Command and DataReader but I got an
> error with DataAdapter.
> Running of SelectCmd and InsertCmd work fine but each UpdateCmd or
> DeleteCmd thrown a DBConcurrencyException.
> It seems that problem is that DataAdapter call ExecuteReader instead
> of ExecuteNonQuery on InsertCmd, UpdateCmd and DeleteCmd. So, number
> of row affected is probably incorrect.
> Do I miss something or is it an usual way of working for a DataAdapter
> ?
> Why ExecuteReader is called for an Update and a Delete without any
> result expected ?
> Thanks in advance for your help or advices.
>
>               Lionel.
Author
31 Dec 2004 5:33 PM
Lionel LASKE
Thanks for your answer but my DataSet don't have any autoinc or timestamp
key and I have just one access on my table (local database).
I tried all enum value in System.Data.UpdateRowSource and I have the same
exception thrown: DBConcurrencyException.
I'm really wonder why for an UPDATE command DbDataAdapter.Update calls my
command with ExecuteReader instead of ExecuteNonQuery. Here is my source
code:


    // ... On init

    dataAdapter = new MyADOProvider.MyDataAdapter(selectCmd);
    dataAdapter.UpdateCommand = new MyADOProvider.MyCommand("MyProc
@action='UPDATE',", cnx);
    dataAdapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
    param = dataAdapter.UpdateCommand.CreateParameter();
    param.DbType = DbType.Int32;
    param.ParameterName = "@code";
    dataAdapter.UpdateCommand.Parameters.Add(param);
    param = dataAdapter.UpdateCommand.CreateParameter();
    param.DbType = DbType.String;
    param.ParameterName = "@name";
    dataAdapter.UpdateCommand.Parameters.Add(param);

    dataSet = new DataSet();
    dataAdapter.Fill(dataSet, "results");


    //... On Update button

    dataAdapter.Update(dataSet, "results");

My guess is that with a ExecuteNonQuery, you can have a "Number of rows
affected" but you can't have this number with a ExecuteReader.
Is someone know the source code of DbDataAdapter.Update ?

                             Lionel.


"Miha Markic [MVP C#]" <miha at rthand com> a écrit dans le message de news:
eGMqrZx7EHA.2***@TK2MSFTNGP10.phx.gbl...
Show quote
> Hi Lionel,
>
> I guess the reader part is because of concurrency issues (to load
> timestamp or autoinc key).
> See help on
> IDbCommand.UpdatedRowSource Property
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> SLODUG - Slovene Developer Users Group
> www.rthand.com
>
> "Lionel LASKE" <lla***@c2s.fr> wrote in message
> news:dfc3550a.0412310037.5509c913@posting.google.com...
>> I'm working on my own implementation of an ADO.NET Data Provider
>> derived from IDbXXXX classes and MSDN sample
>> (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconImplementingNETDataProvider.asp).
>> All is fine when I execute simple Command and DataReader but I got an
>> error with DataAdapter.
>> Running of SelectCmd and InsertCmd work fine but each UpdateCmd or
>> DeleteCmd thrown a DBConcurrencyException.
>> It seems that problem is that DataAdapter call ExecuteReader instead
>> of ExecuteNonQuery on InsertCmd, UpdateCmd and DeleteCmd. So, number
>> of row affected is probably incorrect.
>> Do I miss something or is it an usual way of working for a DataAdapter
>> ?
>> Why ExecuteReader is called for an Update and a Delete without any
>> result expected ?
>> Thanks in advance for your help or advices.
>>
>>               Lionel.
>
>
Author
1 Jan 2005 9:40 AM
Miha Markic [MVP C#]
"Lionel LASKE" <lla***@c2s.fr> wrote in message
news:41d58d72$0$21437$636a15ce@news.free.fr...
>
> Thanks for your answer but my DataSet don't have any autoinc or timestamp
> key and I have just one access on my table (local database).
> I tried all enum value in System.Data.UpdateRowSource and I have the same
> exception thrown: DBConcurrencyException.
> I'm really wonder why for an UPDATE command DbDataAdapter.Update calls my
> command with ExecuteReader instead of ExecuteNonQuery. Here is my source
> code:

Hmm, I don't see any UpdateRowSource setting in your code.

Show quote
>
>    // ... On init
>
>    dataAdapter = new MyADOProvider.MyDataAdapter(selectCmd);
>    dataAdapter.UpdateCommand = new MyADOProvider.MyCommand("MyProc
> @action='UPDATE',", cnx);
>    dataAdapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
>    param = dataAdapter.UpdateCommand.CreateParameter();
>    param.DbType = DbType.Int32;
>    param.ParameterName = "@code";
>    dataAdapter.UpdateCommand.Parameters.Add(param);
>    param = dataAdapter.UpdateCommand.CreateParameter();
>    param.DbType = DbType.String;
>    param.ParameterName = "@name";
>    dataAdapter.UpdateCommand.Parameters.Add(param);
>
>    dataSet = new DataSet();
>    dataAdapter.Fill(dataSet, "results");
>
>
>    //... On Update button
>
>    dataAdapter.Update(dataSet, "results");
>
> My guess is that with a ExecuteNonQuery, you can have a "Number of rows
> affected" but you can't have this number with a ExecuteReader.
> Is someone know the source code of DbDataAdapter.Update ?

Sure, try with Reflector.
http://www.aisto.com/roeder/dotnet/

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com
Author
3 Jan 2005 11:21 AM
Lionel LASKE
"Miha Markic [MVP C#]" <miha at rthand com> a écrit dans le message de news:
ebA$vX%237EHA.3***@TK2MSFTNGP15.phx.gbl...
Show quote
>
> "Lionel LASKE" <lla***@c2s.fr> wrote in message
> news:41d58d72$0$21437$636a15ce@news.free.fr...
>>
>> Thanks for your answer but my DataSet don't have any autoinc or timestamp
>> key and I have just one access on my table (local database).
>> I tried all enum value in System.Data.UpdateRowSource and I have the same
>> exception thrown: DBConcurrencyException.
>> I'm really wonder why for an UPDATE command DbDataAdapter.Update calls my
>> command with ExecuteReader instead of ExecuteNonQuery. Here is my source
>> code:
>
> Hmm, I don't see any UpdateRowSource setting in your code.
>

Of course, I deleted it before publishing here. You can believe me : I made
the test :-)

Show quote
>>
>>    // ... On init
>>
>>    dataAdapter = new MyADOProvider.MyDataAdapter(selectCmd);
>>    dataAdapter.UpdateCommand = new MyADOProvider.MyCommand("MyProc
>> @action='UPDATE',", cnx);
>>    dataAdapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
>>    param = dataAdapter.UpdateCommand.CreateParameter();
>>    param.DbType = DbType.Int32;
>>    param.ParameterName = "@code";
>>    dataAdapter.UpdateCommand.Parameters.Add(param);
>>    param = dataAdapter.UpdateCommand.CreateParameter();
>>    param.DbType = DbType.String;
>>    param.ParameterName = "@name";
>>    dataAdapter.UpdateCommand.Parameters.Add(param);
>>
>>    dataSet = new DataSet();
>>    dataAdapter.Fill(dataSet, "results");
>>
>>
>>    //... On Update button
>>
>>    dataAdapter.Update(dataSet, "results");
>>
>> My guess is that with a ExecuteNonQuery, you can have a "Number of rows
>> affected" but you can't have this number with a ExecuteReader.
>> Is someone know the source code of DbDataAdapter.Update ?
>
> Sure, try with Reflector.
> http://www.aisto.com/roeder/dotnet/
>

Waaooo!!! Reflector is really a great tool but my first look on source code
for System.Data.Common.DbDataAdapter.Update give me more new questions than
anwser... :-(

Show quote
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> SLODUG - Slovene Developer Users Group
> www.rthand.com
>
Author
3 Jan 2005 11:39 AM
Miha Markic [MVP C#]
"Lionel LASKE" <lla***@c2s.fr> wrote in message
news:u4RDsZY8EHA.3840@tk2msftngp13.phx.gbl...
>

> Waaooo!!! Reflector is really a great tool

Indeed :-)

but my first look on source code
> for System.Data.Common.DbDataAdapter.Update give me more new questions
> than anwser... :-(

Not trivial, eh-

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

AddThis Social Bookmark Button