Hello!
Below is a simple program that works fine.
In this program there is no explicit open for the SqlConnection instead
the DataAdapter will open the Connection to the database automatically.
Now to my question if I check the connection after the SqlDataAdapter has
been created the connection is then closed ?
So when does the SqlDataAdapter open and close the DataAdapter ?
static void Main(string[] args)
{
//Specify SQL Server-specific connection string
SqlConnection thisConnection = new SqlConnection(
@"Server=UHT-DEMO1; Integrated Security=True;" +
"Database=northwind");
//Create DataAdapter object
SqlDataAdapter thisAdapter = new SqlDataAdapter(
"Select CustomerID, ContactName from Customers,
thisConnection);
ConnectionState state1 = thisConnection.State;
//Create DataSet to contain related data tables, rows and
columns
DataSet thisDataSet = new DataSet();
//Fill DataSet using query defined previously for DataAdapter
thisAdapter.Fill(thisDataSet, "Customers");
foreach (DataRow theRow in thisDataSet.Tables["Customers"].Rows)
Console.WriteLine("Row = {0}", theRow["CustomerID"] + "\t" +
theRow["ContactName"]);
Console.WriteLine("Program finished, press Enter/Return to
continue");
Console.Read();
}