string sex;
        if (rbtnMan.Checked)
        {
            sex = "男";
        }
        else
        {
            sex = "女";
        }
        string pathString;
        pathString = Server.MapPath("dataBase\\dataBase.mdb");        OleDbConnection con = DB.con(pathString);
        con.Open();        OleDbCommand cmd = new OleDbCommand("select count(*) from userInfo", con);
        int count = Convert.ToInt32(cmd.ExecuteScalar());        int ID = count + 1;
        string name, pwd, url;
        name = txtUserName.Text;
        pwd = txtUserPwd.Text;
        url = txtUserFaceURL.Text;        OleDbCommand InsertCmd = new OleDbCommand("insert into userInfo(userID,userMail,userPassword,userSex,userFaceURL) values("+ID+",'"+name+"','"+pwd+"','"+sex+"','"+url+"')",con);        try
        {
            InsertCmd.ExecuteNonQuery();
        }
        catch (OleDbException ex)
        {
            string errorMessages = "";            for (int i = 0; i < ex.Errors.Count; i++)
            {
                errorMessages += "Index #" + i + "<br/>" +
                                 "Message: " + ex.Errors[i].Message + "<br/>" +
                                 "NativeError: " + ex.Errors[i].NativeError + "<br/>" +
                                 "Source: " + ex.Errors[i].Source + "<br/>" +
                                 "SQLState: " + ex.Errors[i].SQLState + "<br/>";
            }            Response.Write(errorMessages);
        }        con.Close();
不知为何始终无法插入数据,捕捉异常为Index #0
Message: 操作必须使用一个可更新的查询。
NativeError: -198839259
Source: Microsoft JET Database Engine
SQLState: 3073高手帮忙下~谢谢~

解决方案 »

  1.   

    pathString   =   Server.MapPath( "dataBase\\dataBase.mdb "); 获取的数据库连接字符串不对,这样获取只是实际路径,并没有引擎
      

  2.   

    我另外有一个类创建连接,代码为
        public static OleDbConnection con(string dataPath)
        {
            string conString;
            conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
            conString += dataPath;
            return new OleDbConnection(conString);
        }///////////////////////////////////////////////////////////pathString       =       Server.MapPath(   "dataBase\\dataBase.mdb   ");   
    pathString只是数据库路径的参数
      

  3.   


    string   pathString; 
    pathString   =   Server.MapPath( "dataBase\\dataBase.mdb "); 
    OleDbConnection   con   =   DB.con(pathString); pathString是数据库的物理地址.
    不是数据库的连接字符串.
    OleDbConnection   con   =   DB.con(应为数据库的连接字符串); 
      

  4.   

    values( "+ID+ ", 看这里
    改成values( '"+ID+ "',少了两个单引号,加上试试看
      

  5.   

    回7楼的:pathString的确是绝对啊,看我2楼的DB类里的函数回6楼的:ID是在数据库里是数字属性,不加单引号。加了也不行
      

  6.   

    pathString   =   Server.MapPath( "dataBase\\dataBase.mdb "); 
    这里是获得虚拟路径,应该这样写的
    pathString   =   Server.MapPath( "/dataBase/dataBase.mdb "); insert   into   userInfo(userID,userMail,userPassword,userSex,userFaceURL)   values( "+ID+ ", ' "+name+ " ', ' "+pwd+ " ', ' "+sex+ " ', ' "+url+ " ') 
    这里是SQL是肯定错了的, ID是值,你把他成变量了.应该改成insert   into   userInfo(userID,userMail,userPassword,userSex,userFaceURL)   values( '"+ID+ "', ' "+name+ " ', ' "+pwd+ " ', ' "+sex+ " ', ' "+url+ " ') 
      

  7.   

    如果使用pathString       =       Server.MapPath(   "/dataBase/dataBase.mdb   ");   的话,路径就会变成网站根目录了。
    例如:d:\inetpub\wwwroot\dataBase\dataBase.mdb  
    但其实我的路径是  d:\inetpub\wwwroot\home\dataBase\dataBase.mdb  这个早上我就错在那了...
    http://topic.csdn.net/u/20071103/10/130519e1-960f-4831-a4af-77baa74fc045.html但是ID用单引号括起来,也是一样的错误提示
      

  8.   

    我重新建了个website测试了一下,插入没问题,为什么单单在这个页面里有问题呢?命名空间有影响么?using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.OleDb;
      

  9.   

    貌似是我的表建的有问题,能否再帮忙看看
    我的数据库挪到其他程序里也出现一样的错误,但还个数据库插入其他数据就可以。
    数据库是这样的ID 文本
    userName 文本
    userPWD 文本
    userSex 文本
    userFaceURL 文本
      

  10.   

    应该是权限的问题
    你数据库放的哪个盘是不是NTFS的,如果是请这样设置:
    右击你数据库文件夹,点属性-安全,添加个users,权限设置为所有试试
    不知道对你有帮助否!
      

  11.   

    ntfs权限问题.n年前写的文章了. 楼主看第7条. 只不过很遗憾,上面没有我的名字.hehehttp://network.ccidnet.com/art/1084/20070925/1224861_1.html
      

  12.   

    http://www.blueidea.com/tech/program/2004/1905.asp
    这里有图片版的.
      

  13.   

    insert   into   userInfo(userID,userMail,userPassword,userSex,userFaceURL)   values( "+ID+ ", ' "+name+ " ', ' "+pwd+ " ', ' "+sex+ " ', ' "+url+ " ') ====================================================
    userID是否为自动编号?
    如果是就把语句改为:
    insert   into   userInfo(userMail,userPassword,userSex,userFaceURL)   values(' "+name+ " ', ' "+pwd+ " ', ' "+sex+ " ', ' "+url+ " ')