因为你的代码中间有异常,所以会总是执行Catch,返回的就是-1.
所以进不了if语句,因为它没有读出数据来,你打断点调试,看看在哪个地方出现了问题,还是根本就没有这条数据?
int i =-1;
try
{
command = new SqlCommand(strSql, connection);
connection.Open();
i= (int)command.ExecuteScalar();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
return i;
路过,学习
应该是走了catch