DataAdapter Question

  • Thread starter Thread starter John
  • Start date Start date
J

John

I am trying to understand what the difference between using new
OleDbDataadapter(sqlString, dbConn) or new OleDbDataAdapter(sqlString,
connString). How is the connection open on the second constructor and when
is the connection is closed?

Thanks
 
John,

da = new OleDbDataAdapter(sqlString, dbConn);
da = new OleDbDataAdapter(sqlString, connString);

The only difference between the two syntaxes is that the
second constructor creates a new OleDbConnection for the
DataAdapter's SelectCommand. In each case, the DataAdapter will
temporarily open the SelectCommand's Connection when you call
DataAdapter.Fill if the Connection is not already open.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.
 
John,

When you pass a connection string into the DataAdapter
constructor, a new closed Connection is created.

If you call DataAdapter.Fill or DataAdapter.Update and the
Connection is closed, it will be opened just for the duration of
the call. This same behavior applies regardless of whether you
passed a connection string or a Connection to the DataAdapter's
constructor.

I hope this information proves helpful, and that the book
helps answer questions like these in the future.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.
 
Back
Top