C#连接SQL Server2008时,cmd.ExecuteReader()出错是怎么回事 问题出在哪了
stringconnection="datasource=(local);uid=sa;pwd=12345;database=xueshengbiao;";using(S...
string connection = "data source =(local);uid=sa;pwd=12345;database=xueshengbiao;";
using (SqlConnection conn = new SqlConnection(connection))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from t-biao";
using (SqlDataReader reader = cmd.ExecuteReader()
{
while (reader.Read())
{
Console.WriteLine(reader.GetString(1));
}
}
} 展开
using (SqlConnection conn = new SqlConnection(connection))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from t-biao";
using (SqlDataReader reader = cmd.ExecuteReader()
{
while (reader.Read())
{
Console.WriteLine(reader.GetString(1));
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询