[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
        public virtual int UpdateExamples() {
            global::System.Data.OleDb.OleDbCommand command = this.CommandCollection[2];
            global::System.Data.ConnectionState previousConnectionState = command.Connection.State;
            if (((command.Connection.State & global::System.Data.ConnectionState.Open) 
                        != global::System.Data.ConnectionState.Open)) {
                command.Connection.Open();
            }
            int returnValue;
            try {
                returnValue = command.ExecuteNonQuery();
            }
            finally {
                if ((previousConnectionState == global::System.Data.ConnectionState.Closed)) {
                    command.Connection.Close();
                }
            }
            return returnValue;
        }
先说一下我的使用环境:vs2005,access2003
我根本就未有使用参数,而这个UpdateExamples也是机器生成的代码,在设计视图->查询生成器里面我的sql代码可以执行,能更新数据到access,但是我调用这个函数,能返回更新的函数大于1,但是重新打开access里面的内容根本就没有遍,我简直是要崩溃了,这几天都在搞更新的问题,是不是还得调用什么东西使数据库更新的啊?求求各位大大能解决一下了,感激不尽!
下面是_commandCollection[2](即CommandCollection[2])的定义:
            this._commandCollection[2] = new global::System.Data.OleDb.OleDbCommand();
            this._commandCollection[2].Connection = this.Connection;
            this._commandCollection[2].CommandText = "UPDATE zgz\r\nSET xm = \'测试者2\', xb = \'女\'\r\nWHERE (xm = \'测试者\')";
            this._commandCollection[2].CommandType = global::System.Data.CommandType.Text;

解决方案 »

  1.   

    this._commandCollection[2].CommandText = "UPDATE zgz\r\nSET xm = \'测试者2\', xb = \'女\'\r\nWHERE (xm = \'测试者\')"; 
    SQL语句里单引号前为什么要加"\"?
      

  2.   

    这个我是不知道啦,自动代码就是这个样子的。我自己参照写的不会有这个的,但是还是不能执行。
    像这个其实都是有成功返回的,就是没有更新到Access里面去这个问题很奇怪,我希望解决的是这个,不知道有谁人能提供参考
      

  3.   

    this._commandCollection[2].ExecuteNonQuery();//怎么没有看到这句呢?
      

  4.   

    这个,
               try { 
                    returnValue = command.ExecuteNonQuery(); 
                } 
    这里不是吗?
      

  5.   

    不要把this._commandCollection[2]指向command,直接给command新建一个,然后设置Connection、commandtext和commandtype,再执行试试呢?
      

  6.   

    这个,我找到原因了,因为access的数据库在编译的时候会复制到输出目录,所以我一直都在查看的是原始数据库Orz