I dragged an SQL table onto a form, it works, but where is the Open() method being called?

  • Thread starter Thread starter Unemployed Programmer
  • Start date Start date
U

Unemployed Programmer

I am trying to learn .NET so that I can get a job. I have Visual Studio 2003
& the MSDE database installed.

I am reading the book "Beginning C# Databases", Huddleston et al, and it
showed how to drag a table onto a form, which would create SqlConnection &
SqlDataAdapter (and then through a link, a DataSet) objects. With a few
properties being set, and a Fill() call on the SqlDataAdapter, I was able to
populate a ListBox control using records from the NorthWind database.

OK, that's great, but then I go on reading how the SqlConnection object must
have the Open() and then later Close() methods be called. However, when I go
through the code that Visual Studio set up, I don't see any call to Open().

Am I missing something? Is this Open() being called somewhere "under the
hood"? Why isn't there an explicit call?

Thanks
 
Hi,

The dataadapters have some built in functionality.
In that is in the start the connection.open

It is preferable with the fill of only one table not to open the connection
seperatly, while with more you can use one connection. Keep in mind that as
you use a connection open with the dataadapter, that you than has to use too
a close or dispose of that connection.

I hope this helps,

Cor
 
Back
Top