OleDbConnection conn=new OleDbConnection(connStr);
OleDbCommand cmd = new OleDbCommand(strSql,conn);
conn.Open();//没问题
cmd.ExecuteNonQuery();//出现异常conn连接没有问题, 我把strSql考到access里面运行也没问题, 很奇怪为什么上面那句会出现异常

解决方案 »

  1.   

    strSql 帖出来啊 提问的技巧你要知道吧
      

  2.   

    try
    {
    conn.Open();//没问题
    cmd.ExecuteNonQuery();//出现异常
    }
    catch(Exception ex)
    {
    Response.Write(ex.ToString());
    ==================================
    你的sql没有参数?你对数据库文件是否有访问得权限?
    }
      

  3.   

    有日文?http://blog.csdn.net/goaler/archive/2004/10/09/129145.aspx
      

  4.   

    在Sql语句里面字段名称是不是有系统的保留字
    比如说id,count,之类的,有的话在字段名称两边加上[]
    例如
    select [ID] ,[NAME],[COUNT] FROM User WHERE [ID] = 2
      

  5.   

    connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\yiudata\data\db.mdb";
    strSql = "insert into users(userID,userPwd,regDate) values('hunter','hunter','1:59 PM')";
    OleDbConnection conn=new OleDbConnection(connStr);
    OleDbCommand cmd=new OleDbCommand(strSql,conn);
    try
    {
        conn.Open ();
        cmd.ExecuteNonQuery ();
        Response.Write ("<script language='javascript'> alert('注册成功') </script>");
        Session["userID"]=this.txtRegUserName.Text ;
        Response.Redirect ("userCenter.aspx");
    }
    catch(System.Exception ex)
    {
        throw new Exception (ex.Message );
    }
    finally
    {
        conn.Close ();
    }
    数据库文件是我自己建的, 所以肯定有权限啊,
      

  6.   

    insert into users(userID,userPwd,regDate) values('hunter','hunter','1:59 PM')"
    放到ACCESS看能不能执行
      

  7.   

    错误信息如下:
    Operation must use an updateable query. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Exception: Operation must use an updateable query.Source Error: 
    Line 86:  catch(System.Exception ex)
    Line 87:  {
    Line 88:  throw new Exception(ex.Message );
    Line 89:  }
    Line 90:  finally
     Source File: c:\inetpub\wwwroot\yiudata\register.aspx.cs    Line: 88 Stack Trace: 
    [Exception: Operation must use an updateable query.]
       yiudata.register.btnReg_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\yiudata\register.aspx.cs:88
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +232
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +5
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5157 
      

  8.   

    to layeryli(小熊维尼):
    insert into users(userID,userPwd,regDate) values('hunter','hunter','1:59 PM')"
    这句可以执行
      

  9.   

    try
    {
        conn.Open ();
        cmd.CommandType = CommandType.Text;
        cmd.ExecuteNonQuery ();
    …………