Vs2005 has been released for a while. Recently, we have seen Article More and more, I couldn't help but install vs2005.
In framwork1.1, datatable generally uses two methods to load data: one from dataset and the other from custom datatable to fill data with datareader, in framwork2.0, some methods are added in addition to these two methods. For example, the abled readxml Method for loading data from XML. Here I will refer to dataadapter. fill Method and datatabled load method.
Used hereCodePOST method writingProgramDrag the gridview control on the page. The background code is as follows:
Example 1:
// Use the fill method to fill the datatable
Private Void Usedatatablebyfill ()
{
Sqlconnection myconnection = New Sqlconnection (configurationmanager. connectionstrings [ " Sqlconnectionstring " ]. Connectionstring );
Datatable mydatatable = New Datatable ();
Sqldataadapter mydp = New Sqldataadapter ( " Select * from authors " , Myconnection );
Mydp. Fill (mydatatable );
Gridview1.datasource = Mydatatable. defaultview;
Gridview1.databind ();
Myconnection. Dispose ();
Mydp. Dispose ();
}
Example 2: // Use the datareader Method
Private Void Usedatatablebydatareader ()
{
Sqlconnection myconnection = New Sqlconnection (configurationmanager. connectionstrings [ " Sqlconnectionstring " ]. Connectionstring );
Datatable mydatatable = New Datatable ();
Sqlcommand mycommand = New Sqlcommand ( " Select * from authors " , Myconnection );
Myconnection. open ();
Sqldatareader Dr = Mycommand. executereader (commandbehavior. closeconnection );
Mydatatable. Load (DR );
Gridview1.datasource = Mydatatable. defaultview;
Gridview1.databind ();
Dr. Close ();
Dr. Dispose ();
Mycommand. Dispose ();
}
You can call these two events to display data.
After testing, we found that the two methods show that the data cannot use the pagination and sorting events that come with the gridview, and the features such as the other events of the gridview and the calculation column of the Abel are not tested.