|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataAdapter call ExecuteReader instead of ExecuteNonQueryI'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. Hi Lionel,
I guess the reader part is because of concurrency issues (to load timestamp or autoinc key). See help on IDbCommand.UpdatedRowSource Property -- Show quoteMiha 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. 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. > > "Lionel LASKE" <lla***@c2s.fr> wrote in message Hmm, I don't see any UpdateRowSource setting in your code.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: Show quote > Sure, try with Reflector.> // ... 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 ? http://www.aisto.com/roeder/dotnet/ -- Miha Markic [MVP C#] - RightHand .NET consulting & development SLODUG - Slovene Developer Users Group www.rthand.com "Miha Markic [MVP C#]" <miha at rthand com> a écrit dans le message de news: ebA$vX%237EHA.3***@TK2MSFTNGP15.phx.gbl...Show quote > Of course, I deleted it before publishing here. You can believe me : I made > "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. > the test :-) Show quote >> Waaooo!!! Reflector is really a great tool but my first look on 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 ? > > Sure, try with Reflector. > http://www.aisto.com/roeder/dotnet/ > 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 > "Lionel LASKE" <lla***@c2s.fr> wrote in message Indeed :-)news:u4RDsZY8EHA.3840@tk2msftngp13.phx.gbl... > > 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 Not trivial, eh-> than anwser... :-( -- Miha Markic [MVP C#] - RightHand .NET consulting & development SLODUG - Slovene Developer Users Group www.rthand.com |
|||||||||||||||||||||||