我正在使用 C# 和 SQL 学习 WinForms。当我执行代码时出现此错误:“System.Data.dll 中出现类型为‘System.Data.SqlClient.SqlException’的未处理异常”
这是代码:
string connetionString;
SqlConnection cnn;
connetionString = @"Data Source=desktop-brvgrif\sqlexpress;Integrated Security=True";
cnn = new SqlConnection(connetionString);
cnn.Open();
SqlCommand command;
SqlDataReader dataReader;
String sql, Output = "";
sql = "SELECT TutorialID,TutorialName from demotb";
command = new SqlCommand(sql, cnn);
dataReader = command.ExecuteReader();
while(dataReader.Read())
{
Output = Output + dataReader.GetValue(0) + " - " + dataReader.GetValue(1) + "\n";
}
MessageBox.Show(Output);
dataReader.Close();
command.Dispose();
cnn.Close();
繁星点点滴滴
相关分类