public void reg_click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
obj.open();
//检查用户ID是否已经被注册
mycommand=new OleDbCommand("select userid from usermain where userid='"+username.Text+"'",obj.link);
    rs=mycommand.ExecuteReader();
if(rs.Read())
{
obj.link.Close();
agreereg.Visible=false;
reg2.Visible=true;
all.Visible=false;
pageerr.InnerHtml="<pre><font color=red><b>注册出错</b></font><br>该用户ID已经被注册,请换一个重试</pre>";
return;
}
rs.Close();
//检查用户EMAIL是否已经被注册
mycommand=new OleDbCommand("select userid from usermain where email='"+mail.Value+"'",obj.link);
rs=mycommand.ExecuteReader();
if(rs.Read())
{
obj.link.Close();
agreereg.Visible=false;
reg2.Visible=true;
all.Visible=false;
pageerr.InnerHtml="<pre><font color=red><b>注册出错</b></font><br>该email地址已经被注册,请换一个重试</pre>";
return;
}
rs.Close();
//提交用户,对用户密码和提示答案加密
string a_password=FormsAuthentication.HashPasswordForStoringInConfigFile(password.Value,"md5");
string a_answer=FormsAuthentication.HashPasswordForStoringInConfigFile(an.Value,"md5");
ViewState["userid"]=username.Text;
//开始添加数据库

string sql="insert into usermain(userid,userpassword,sex,email,passq,passa) values('"+username.Text+"','"+a_password+"','"+sex.Value+"','"+mail.Value+"','"+qu.Value+"','"+a_answer+"')";   
mycommand=new OleDbCommand("insert into usermain(userid,userpassword,sex,email,passq,passa) values('"+username.Text+"','"+a_password+"','"+sex.Value+"','"+mail.Value+"','"+qu.Value+"','"+a_answer+"')",obj.link);
Response.Write("<srcipt>alert(sql)</script>");
mycommand.ExecuteNonQuery(); //注册成功,弹出窗口提示。然后转向下一步注册
obj.link.Close();
Response.Write("<script>alert('注册成功,点击确定,填写用户详细信息')</script>");
agreereg.Visible=false;
reg2.Visible=false;
all.Visible=true;
}
}运行时候提示出错,小弟不才,看不出来错在那里??操作必须使用一个可更新的查询。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.OleDb.OleDbException: 操作必须使用一个可更新的查询。源错误: 
行 116: mycommand=new OleDbCommand("insert into usermain(userid,userpassword,sex,email,passq,passa) values('"+username.Text+"','"+a_password+"','"+sex.Value+"','"+mail.Value+"','"+qu.Value+"','"+a_answer+"')",obj.link);
行 117: Response.Write("<srcipt>alert(sql)</script>");
行 118: mycommand.ExecuteNonQuery();
行 119:
行 120: //注册成功,弹出窗口提示。然后转向下一步注册
 

解决方案 »

  1.   

    检查一个access的写入权限。
    ------说错了莫怪。
      

  2.   

    我打开了access,确实是只读的属性,怎么取消啊
      

  3.   

    去掉只读就可。另外给aspne(iis5) 或network service(iis6) 用户写入权限。如果是fat32文件系统,则不用考虑。
    ------说错了莫怪。
      

  4.   

    谢谢cpp2017(幕白兄) ,搞定了,IIS 里写入权限,说的很对,我的文件系统是NTFS。
    真的谢谢大哥。