.NET中数据更新的问题
做了个更新,但是更新不了数据库,断点设置能执行,又找不出错在哪里。郁闷啊!!!
class user代码为:
public int UpdateUserPartPim(int userid, string realname, string sex, string grade, string sclass, string province, string county, string address, string sectionnum, string phone, string email)
{
SqlConnection myCon = new SqlConnection(
ConfigurationManager.ConnectionStrings[ "mySQLcon "].ConnectionString);
string cmdText = "update users set realname= ' " + realname + " ',sex = ' " + sex + " ',grade = ' " + grade + " ',class = ' " + sclass + " ',province = ' " + province + " ',county = ' " + county + " ',address = ' " + address + " ',sectionnum= ' " + sectionnum + " ',phone = ' " + phone + " ',email = ' " + email + " 'where userid = ' "+ userid.ToString()+ " ' ";
SqlCommand myCmd = new SqlCommand(cmdText,myCon);
int nresult = -1;
myCon.Open();
nresult = myCmd.ExecuteNonQuery;
myCon.Close();
return nresult;
}
引用文件的代码为:
protected void enterbtn_Click(object sender, EventArgs e)
{
User user = new User();
user.UpdateUserPartPim(userid, realname.Text.Trim(), sex.SelectedValue, grade.Text.Trim(), sclass.Text.Trim(), province.Text.Trim(), county.Text.Trim(), address.Text.Trim(), sectionnum.Text.Trim(), phone.Text.Trim(), email.Text.Trim());
Response.Redirect( "userpartpim.aspx ");
}
[解决办法]
楼主仔细一点,这样的问题,仔细一点就不会出现了