Data adapters always use ExecuteReader? RRS feed

  • Question

  • The following pertains to my use of Visual Studio 2005 (i.e., .NET Framework 2.0 and ADO.NET 2.0):


    When you call the OleDbDataAdapter's Update method, does it always call the ExecuteReader method? For instance, when I've inserted a row in a DataTable and pass the table to an OleDbDataAdapter's Update method, the data adapter uses the command object assigned to its InsertCommand property. My question is, when the data adapter executes this command, does it always do so using the ExecuteReader method of the command? If so, is this behavior the same for all data providers (i.e., all types derived from DbDataAdapter)?


    I'm particularly interested in OleDb because, besides the fact that I'm connecting to an Access database, I'm exploring how ADO.NET makes use of the OleDbCommand's UpdatedRowSource property. If the ExecuteReader method is always called by the adapter, then it is always an option to set the UpdatedRowSource property to Both, as long as the query used can return rows. But...


    Since OleDb does not support batch queries (at least not batches with size greater than 1), I'm assuming Insert, Update, and Delete OleDbCommands cannot return rows. Also, I'm not aware of any way to create output parameters in OleDb. For all intents and purposes, then, it seems that the UpdatedRowSource property is of no use for OleDbCommands.


    So why would the OleDbDataAdapter use the ExecuteReader method instead of the ExecuteNonQuery method when using commands whose command text are action queries. Because the adapter doesn't know what kind of query the command will use, and ExecuteReader is a kind of general purpose use of the command? Otherwise, it would seem to make more sense in OleDb for the adapter to use ExecuteNonQuery for its InsertCommand, UpdateCommand, and DeleteCommand commands and get rows affected as the result, instead of using ExecuteReader and checking the RecordsAffected property of the returned reader.


    Anyway, please answer these main questions: Does the OleDbDataAdapter always call the ExecuteReader method of the OleDbCommands that it uses? Is this the same for all providers, for all adapters deriving from DbDataAdapter?

    Wednesday, June 11, 2008 8:13 PM