.NET连接数据库 报这个错误 什么情况?新手求指导
string connString = "Data Source=.;Initial Catalog=myfrist;User Id=sa;Pwd=root";
SqlConnection connection = new SqlConnection(connString);
int num = 0;
String message = "";
string Sql = "select count(*) from Table_1 ";
try
{
connection.Open();
SqlCommand command = new SqlCommand(Sql, connection);
num = (int)command.ExecuteScalar();
message = string.Format("当前共有{0}条记录", num);
MessageBox.Show(message, "查询结果", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally {
connection.Close();
}
[align=center][/align]代码有错吗?
------解决方案--------------------
是不是数据库连接语句出错啦,密码,用户名,数据库必须要对才能连上数据库呢
------解决方案--------------------