报错!高手指点!!!!谢谢了!!!!
public static bool AdminLogin(Admin ad)
{
using (DataBase db = new DataBase())
{
SqlCommand com = new SqlCommand();
com.Connection = db.Connection;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "dbo.hs_AdminLogin";
com.Parameters.Add("@aName",SqlDbType.VarChar,100).Value = ad.aName;
com.Parameters.Add("@aPwd", SqlDbType.VarChar, 100).Value = ad.aPwd;
int count = Convert.ToInt32(com.ExecuteScalar());
return count > 0 ? true : false;
}
}
报这个错:
ExecuteScalar: Connection property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: ExecuteScalar: Connection property has not been initialized.
Source Error:
Line 92: com.Parameters.Add("@aName",SqlDbType.VarChar,100).Value = ad.aName;
Line 93: com.Parameters.Add("@aPwd", SqlDbType.VarChar, 100).Value = ad.aPwd;
Line 94: int count = Convert.ToInt32(com.ExecuteScalar());
Line 95: return count > 0 ? true : false;
Line 96: }