Disconnected data model

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();
}
 
W

William Ryan

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
 
W

William Ryan

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
 
A

Alex

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top