Let's continue with the previous content. Oh, this time we mainly talk about the powerful functions of DataSet :). The previous one blew everyone's
Bubble (the meaning of the words is not counted, so Hunan people can understand it). This time, we will not be able to say anything again :)
Store multiple data tables in one DataSet
Many of us are used to using RecordSet objects to operate databases in ASP, but there is a shortage of RecordSet objects.
Point is that A RecordSet can only store one data table. When we need to operate multiple tables, we have
Although there is nothing to do with these operations in cordSet, this is also true for a newbie.
A very troublesome thing. Just those variable names can confuse you. Now, in ASP. Net, you only need
One DataSet can handle everything. This greatly facilitates our program. We are still the same. Let's take a look at Cheng.
For more information.
<% @ Page Language = "C #" %>
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Data. ADO" %>
<Script Language = "C #" Runat = "Server">
Public void Page_Load (Object src, EventArgs e)
{
// Join statement
String MyConnString = "Driver = {Microsoft Access Driver (*. mdb )};
DBQ = c:/test. mdb ;";
String strComm1 = "select * from UserList ";
String strComm2 = "select * from BookList ";
// Open a connection
ADOConnection MyConnection = new ADOConnection (MyConnString );
// Open two datasetcommands
ADODataSetCommand MyComm1 = new ADODataSetCommand (strComm1, MyConnection );
ADODataSetCommand MyComm2 = new ADODataSetCommand (strComm2, MyConnection );
DataSet MyDataSet = new DataSet ();
// Store the UserList and BookList tables into DataSet
MyComm1.FillDataSet (MyDataSet, "UserList ");
MyComm2.FillDataSet (MyDataSet, "BookList ");
DataGrid1.DataSource = MyDataSet. Tables ["UserList"]. DefaultView;