Basic steps for programming using ADO.NET database

xiaoxiao2021-03-06  42

Basic steps for programming using ADO.NET database:

1. Create a connection string:

String Connectionstring = "Server = .; uid = sa; pwd =; database = northwind";

2. Create a SELECT statement string:

String commandstring = "Select CompanyName, ContactName from Customers";

3. Create DataAdapter and pass the connection string and command string:

SqlDataAdapter DataAdapter = New SqldataAdapter (CommandString, Connectionstring);

4. Create a new DataSet:

DataSet DataSet = New DataSet ();

5. Use DataAdapter to add data in the Customers table to DataSet:

DataAdapter.Fill (DataSet, "Customers");

6, extract DataTable from DataSet:

DataTable DataTable = Dataset.tables [0];

7. Use the data in DataTable, the following code is to populate the data into the list box.

Foreach (DataRow DataRow In DataTable.Rows)

{

LBCUSTOMERS.ITEMS.Add ("CompanyNAME"] ") (" DATAROW ["ContactName"] ")")

}

转载请注明原文地址:https://www.9cbs.com/read-78944.html

New Post(0)