这段代码在 Visual Studio 2012 中给了我以下错误
SqlConnection conn = new SqlConnection(
ConfigurationManager.ConnectionString["erpConnStr"].ConnectionString);
conn.Open();
String validateUserQry = "SELECT * FROM members WHERE username = '" + username.Text + "'";
SqlCommand validateUserComm = new SqlCommand(validateUserQry, conn);
validateUserComm.ExecuteNonQuery();
if (validateUserComm.ExecuteScalar().ToString() == null)
{
errorMsg.Visible = true;
msg.Text = "Username was not Correct ! ";
}
错误是:
你调用的对象是空的。
我可以说错误发生在这一行:
if (validateUserComm.ExecuteScalar().ToString() == null)
为什么?