using SystemData; // Use ADONET namespace
using SystemDataSqlClient;
SqlConnection thisConnection = new SqlConnection(
@Data Source=GY; Initial Catalog=northwind;uid=sa;password=datadog); //先建立连接
thisConnectionOpen();//打开连接
SqlCommand thisCommand = thisConnectionCreateCommand();//直接指定conn的command
也可以这样 // SqlCommand cmd = new SqlCommand();
// cmdConnection = thisConnection;
cmmand的sql命令
thisCommandCommandText = SELECT CustomerID CompanyName from Customer;
SqlDataReader thisReader = thisCommandExecuteReader();//sqldatareader不可以用new 必须直接与command关联
//用reader读出表
while (thisReaderRead())
{
// Output ID and name columns
ConsoleWriteLine(\t{}\t{}
thisReader[CustomerID] thisReader[CompanyName]);
// Close reader 用完要关闭
thisReaderClose();
// Close connection
thisConnectionClose ()