数据库插值问题
提示: VS2005 并不报错 也就是没有语法错误 可是数据库中没有插入的数据,设置断点编译表明reVale 的值为0
也就是说 reVale = db.sqlEx(cmdstr); 调用方法出现问题
protected void btnRegister_Click(object sender, EventArgs e)
{
int reVale = CheckName();
if (reVale == 1)
{
Response.Write(db.MessageBox("该用户存在,请重新设置!", "Register.aspx"));
}
else
{
string UserName = this.txtUserName.Text;
string PassWord = this.txtPwd.Text;
string Emial = this.txtEmail.Text;
string cmdstr = "insert into tb_User(UserName,PassWord,Emial)Values('" + UserName + "','" + PassWord + "','" + Emial + "')";
try
{
reVale = db.sqlEx(cmdstr);
if (reVale == 1)
{
Response.Write(db.MessageBox("注册成功!", "Register.aspx"));
Clear();//清空文本框
}
else if (reVale == 0)
{
Response.Write(db.MessageBox("注册失败!", "Register.aspx"));
}
}
catch
{
Response.Write(db.MessageBox("注册失败!", "Register.aspx"));
}
}
}
public int sqlEx(string cmdstr)
{
SqlConnection con = new SqlConnection(connstring);
con.Open();
SqlCommand cmd = new SqlCommand(cmdstr, con);
try
{
cmd.ExecuteNonQuery();//执行这一句出现异常
return 1;
}
catch (Exception e)
{
return 0;
}
finally
{
con.Dispose();
}
}