Sql server Winform中的System.Data.dll中发生类型为“System.Data.SqlClient.SqlException”的未处理异常
我正在使用SQL Server 2014,以下是我的代码:Sql server Winform中的System.Data.dll中发生类型为“System.Data.SqlClient.SqlException”的未处理异常,sql-server,winforms,exception,Sql Server,Winforms,Exception,我正在使用SQL Server 2014,以下是我的代码: void loadProductsInfor() { SqlConnection con = new SqlConnection(); con.ConnectionString = @"server=.\SQLEXPRESS;database=CNET_Block3;uid=sa;pwd=123456;integrated security=true"; con.Open(); SqlComm
void loadProductsInfor()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = @"server=.\SQLEXPRESS;database=CNET_Block3;uid=sa;pwd=123456;integrated security=true";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Products";
SqlDataReader dr = cmd.ExecuteReader(); // Exception happens here
while (dr.Read())
{
dataGridView1.Rows.Add(dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString(), dr[4].ToString(), dr[5].ToString(), dr[6].ToString(), dr[7].ToString(), dr[8].ToString(), dr[9].ToString(), dr[10].ToString());
}
dr.Close();
con.Close();
}
我尝试了很多东西,但都不管用。你尝试了什么?此外,无论何时需要异常帮助,都需要发布完整的异常。仅出于故障排除目的,添加以下代码:尝试{/*此处的代码*/}捕获异常ex{MessageBox.Showex.ToString;throw;}然后使用ex.ToString的结果编辑您的问题。看在上帝的份上,将sa密码从123456更改为123456。一个白痴的行李上会有这种东西