For most original programmers who have written ASP programs, they are still very emotional for ADO Recordset. Although in .NET has already replaced ADO Recordset, ADO Recordset is still very useful when handling some interface programs, especially when we call a COM returned to an ADO Recordset type in .NET. When you read the following instructions, you will find it so easy. Results as shown below:
Here we use A DataGrid and a DropdownList, they help them to the same data source. The data source is based on the Northwind database. In fact, we can't bind the ASP.NET control to the ADO Recordset, we need to add a reference: AdoDB Library. In our engineering References folder, right click, select Add a reference, select the COM page, join Microsoft ActiveX Data Objects 2.7 Library. The specific code is as follows:
private void Bind () {OleDbDataAdapter custDA = new OleDbDataAdapter (); DataTable dtTerritories = new DataTable ( "Territories"); ADODB.Connection adoConn = new ADODB.Connection (); ADODB.Recordset adoRS = new ADODB.Recordset (); adoConn .Open ("provider = sqloledb; data source = localhost; initial catalog = northwind; user ID =
Password =
;", "", "", -1);
Adors.open ("Select TerritoryId, TerritoryDescription", Adoconn, AdoDb.cursortypeenum.adopenforwardonly, AdoDb.lockTypeenum.adlockReadonly, 1);
Custda.Fill (DTTERRITORIES, Adors);
Adors.close ();
Adoconn.close ();
Adors = NULL;
Adoconn = NULL;
DataGrid1.datasource = DTTERRITORIES DITAGRID1.DATASOURCE
DataGrid1.databind ();
DROPDOWNLIST1.DATASOSOURCE = DTTERRITORIES;
DropDownList1.DataValuefield = "territoryid";
DropDownList1.datatextField = "TerritoryDescription";
DropDownList1.DATABIND ();
}