T
Tony
Hello!
I'm reading a book called "Programming Microsoft ADO.NET 2.0 Core Reference
by David Sceppa"
And there is something that I don't really understand here.
This is copied from the book first a piece of code then below I have some
text also copied from the book.
string strConn, strSQL;
strConn = "@Data Source=.\SQLEXPRESS; Initial Catalog=Northwind;Integrated
Security";
strSQL = "select CustomerID, CompanyName from Customers";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter (strSQL, strConn);
da.Fill(ds);
foreach(DataRow row in ds.Tables[0].Rows)
Console .WriteLine("{0} - {1}", row["CustomerID"], row["CompanyName"]);
Once this call completes, there is no connection between the two objects.
The DataSet does not maintain a reference, internally or externally to the
SqlDataAdapter and the SqlDataAdapter does not maintain a reference to the
DataSet. Also the DataSet contain no information indicating where the data
originated - no connection string, no table name. The DataSet does contain
the column names by default but these column names do not need to match the
names of the columns in your database table. Thus you can pass DataSet
objects from your middle-server to your client application without
divulging any information about the location or structure of your database.
Now what seems strange to me is that the text says that the SqlDataAdapter
doesn't have a reference to the DataSet.
How is it then possible for the SqlDataAdapter to perform update in the
database for the changes that have been made in the dataset if the
SqlDataAdapter doesn't have a reference to the dataset ?
Here is how SqlDataAdapter will perform update in the dataset da.Update(ds);
//Tony
I'm reading a book called "Programming Microsoft ADO.NET 2.0 Core Reference
by David Sceppa"
And there is something that I don't really understand here.
This is copied from the book first a piece of code then below I have some
text also copied from the book.
string strConn, strSQL;
strConn = "@Data Source=.\SQLEXPRESS; Initial Catalog=Northwind;Integrated
Security";
strSQL = "select CustomerID, CompanyName from Customers";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter (strSQL, strConn);
da.Fill(ds);
foreach(DataRow row in ds.Tables[0].Rows)
Console .WriteLine("{0} - {1}", row["CustomerID"], row["CompanyName"]);
Once this call completes, there is no connection between the two objects.
The DataSet does not maintain a reference, internally or externally to the
SqlDataAdapter and the SqlDataAdapter does not maintain a reference to the
DataSet. Also the DataSet contain no information indicating where the data
originated - no connection string, no table name. The DataSet does contain
the column names by default but these column names do not need to match the
names of the columns in your database table. Thus you can pass DataSet
objects from your middle-server to your client application without
divulging any information about the location or structure of your database.
Now what seems strange to me is that the text says that the SqlDataAdapter
doesn't have a reference to the DataSet.
How is it then possible for the SqlDataAdapter to perform update in the
database for the changes that have been made in the dataset if the
SqlDataAdapter doesn't have a reference to the dataset ?
Here is how SqlDataAdapter will perform update in the dataset da.Update(ds);
//Tony