未将对象引用设置到对象的实例
protected void Page_Load(object sender, EventArgs e)
{
string userName = Request.Form["txtUserName"].ToString();
string userPwd = Request.Form["txtUserPwd"].ToString();
SqlConnection con = new SqlConnection("server=.;database=Login;uid=sa;pwd=123;");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from login where userName='" + userName + "' and userPwd='" + userPwd + "'", con);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
Response.Redirect("main.aspx");
}
else
{
Response.Redirect("loginFail.htm");
}
}
调试时出现如下错误:
未将对象引用设置到对象的实例
怎么解决???~~~~