Disconnected data model

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

When I use SqlCommand directly instead of using DataAdapter/DataSet model,
f.e. I open the connection, execute the query and then close it virtually
right away(the exception handling should it get there is just a few
instructions). Isn't this really what DataAdapter does underneath, I'm just
not going through the DataAdapter wrapper? Btw, does the Connection time out
have a default value?

SqlConnection conn = new SqlConnection(connString);
SqlCommand procAddCustomer = new SqlCommand("procAddCustomer", conn);

procAddCustomer.CommandType = CommandType.StoredProc;

// Add parameters to comand's parameters collection
.....

conn.Open();

try
{
procAddCustomer.ExecuteNonQuery();
}
catch(SqlException e)
{
// handle exception
}
finally
{
conn.Close();
}
 
Yes, you are correct about opening and closing. As a
matter of fact, when a DataAdapter fills a table, it
actually uses a DataReader and populates at DataTable with
that info. However, you DataReaders aren't enumerable,
and they can't accept changes and then submit them
afterward.

The default timeout is 15 seconds, but if you want to
change it, do it in the connection string b/c the timeout
property of the connection object is read only.

Good Luck,

Bill
 
Remember one last thing...MS draws a distinction between
ADO.NET in Connected and Disconnected Mode. Using the
Readers and command objects such as ExcecuteScalar and
ExecuteNonQuery is considered 'connected', Using a
DataAdapter to move the data back and forth, or declaring
datatables/datasets locally and creating them without a
server is the disconnected model.

Franseco Balena's VB.NET core Reference, and more
Particularly , David Sceppa's ADO.NET Core Reference are
great references.

Good Luck,

Bill
 
Remember one last thing...MS draws a distinction between
ADO.NET in Connected and Disconnected Mode. Using the
Readers and command objects such as ExcecuteScalar and
ExecuteNonQuery is considered 'connected', Using a
DataAdapter to move the data back and forth, or declaring
datatables/datasets locally and creating them without a
server is the disconnected model.

Yeah, but while the DataAdapter uses a DataReader to fill the DataSet it is
connected. It's just afterwards it's disconnected using the DataSet to bind
to Grids, Repeaters, etc.... How is that any different then my disconnected
ArrayList representing the resultset that I will bind to server controls?
It's just that my ArrayList of business type has a lot less capablities then
the DataSet, but both are disconnected.
 
Back
Top