数据库连接问题
我是一名新秀,刚学C#,在连接数据库的时候老师出错,望指点,连接代码如下:SqlConnection thisConnection = new SqlConnection(
@"Server=(local);Integrated Security=True;" +
"Database=northwind");
//打开连接
thisConnection.Open();
//创建命令
SqlCommand thisCommand = thisConnection.CreateCommand();
//查询语句
=
"SELECT CustomerID ,CompanyName from Customers";
//执行DataReader
SqlDataReader thisReader = thisCommand.ExecuteReader();
//while there are rows to read
while (thisReader.Read())
{
//输出ID 和 NAME 行
Console.WriteLine("\t{0}\t{1}",
thisReader["CustomerID"], thisReader["CompanyName"]);
}
//关闭 Reader
thisReader.Close();
//关闭连接
thisConnection.Close();
Console.WriteLine("Programe finished ,press enter/return to continue");
Console.ReadKey();