新手第一次做,调试了很多遍,出现了大量的异常,往数据库插值一直实现不了,哭了
,问题出现在cmd1.ExecuteNonQuery();这里
protected void Button1_Click(object sender, EventArgs e)
{
string vusername = username.Text.Trim();
string vpassword = password.Text.Trim();
string vvname = vname.Text.Trim();
string vsex = sex.SelectedItem.Text.ToString();
string vid = sid.Text.Trim();
string vphone = phonenumber.Text.Trim();
string vmail = mail.Text.Trim();
string vtype="Visitor";
string sqltext = "select * from AllUser where username='" + vusername + "'";
string sqltext1 = "insert into AllUser(username,password,type) values('" + vusername + "','" + vpassword + "','" + vtype + "')";
string sqltext2 = "insert into Visitor(username,vname,sex,id,phonenumber,mail) values('"+vusername+"','"+vvname+"','"+vsex+"','"+vid+"','"+vphone+"','"+vmail+"')";
try
{
string connStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Travel Self-help System\App_Data\Travel.MDF;Integrated Security=True;User Instance=True";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand cmd = new SqlCommand(sqltext, conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Write("<script>alert('用户名已存在!');</script>");
Response.Redirect("VisitorRegister.aspx");
}
else
{
SqlCommand cmd1 = new SqlCommand(sqltext1, conn);
cmd1.ExecuteNonQuery();
SqlCommand cmd2 = new SqlCommand(sqltext2, conn);
cmd2.ExecuteNonQuery();
Response.Write("<script>alert('注册成功!');</script>");
Response.Redirect("Login.aspx");
/*if (cmd1.ExecuteNonQuery()>0&&cmd2.ExecuteNonQuery()>0)
{
Response.Write("<script>alert('注册成功!');</script>");
Response.Redirect("Login.aspx");
}*/
}
conn.Close();
}
catch
{
Response.Write("出现错误,请检查您的填写");
Response.End();
}
}
异常主要有:
在 System.Web.HttpException 中第一次偶然出现的“System.Web.dll”类型的异常 其他信息:无法验证数据
在 System.Web.HttpException 中第一次偶然出现的“System.Web.dll”类型的异常
在 System.UnauthorizedAccessException 中第一次偶然出现的“mscorlib.dll”类型的异常
在 System.InvalidOperationException 中第一次偶然出现的“System.Web.dll”类型的异常
在 System.UnauthorizedAccessException 中第一次偶然出现的“mscorlib.dll”类型的异常
在 System.InvalidOperationException 中第一次偶然出现的“System.Web.dll”类型的异常
在 System.InvalidOperationException 中第一次偶然出现的“System.Web.dll”类型的异常
在 System.UnauthorizedAccessException 中第一次偶然出现的“mscorlib.dll”类型的异常
在 System.InvalidOperationException 中第一次偶然出现的“System.Web.dll”类型的异常
在 System.InvalidOperationException 中第一次偶然出现的“System.Web.dll”类型的异常
在 System.UnauthorizedAccessException 中第一次偶然出现的“mscorlib.dll”类型的异常
在 System.InvalidOperationException 中第一次偶然出现的“System.Web.dll”类型的异常