关于抛出异常未处理SqlExceptin的问题
一个简单的查询,在love里面查询student表里面的记录。抛出异常显示未处理SqlExceptin
如下图;
我想代码没问题,在网上查说是配置的问题,但是我怎么弄都不行。我用的是sql 2008 R2以下是代码:
private void btn1_Click(object sender, EventArgs e)
{
string conneString = "Data Source=.;Initial Catalog=love;Integrated Security=True";
SqlConnection connection=new SqlConnection (conneString );
int num = 0;
string message = "";
string sql = "SELECT COUNT(*) FORM student";
try
{
connection.Open();
SqlCommand command = new SqlCommand(sql, connection);
num = (int)command.ExecuteScalar();
message = string.Format("Student表中有{0}条学员信息", num);
MessageBox.Show(message, "查询结果", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("打开成功");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw;
}
finally
{
connection.Close();
MessageBox.Show("关闭成功");
}
}
刚接触asp.net 的新人。请前辈们给个解决方法。多多指教,谢谢 ,谢谢
------解决方案--------------------FORM ---> FROM