当开始update时,根据dataset.table["table1"].Rows[index].RowState 来依次判断如果不是UnChanged就说明发生了改动,然后再选择调用INSERT/DELETE/UPDATE来对DB中的源数据库进行改动?那么在command中,比如OdbcCommand cmdins = new OdbcCommand("Insert into table1(code,name,control) values(@code,@name,@control)", Myconnection);cmdins.Parameters.Add("@code", OdbcType.Int, 11,"code");
..... da.InsertCommand = cmdins;中,"code"这个参数,VS05提示里只说是sourcecolumn,到底是指DB table中的column,还是dataset的table里对应的column名?

解决方案 »

  1.   

    你想想看,如果是table中的code,那么,@code这个参数应该由谁提供呢?如果没有提供,那么insert语句插入时就会产生错误,是不是?
      

  2.   

    我写了一段测试代码如下:
    string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +
                 "SERVER=localhost;" +
                 "DATABASE=vs_db;" +
                 "UID=root;" +
                 "PASSWORD=;" +
                 "OPTION=3";
                dbcConnection Myconnection = new OdbcConnection(MyConString);
                Myconnection.Open();
                DataSet ds = new DataSet();
                string tablename = "table1";
                string sql = "select * from table1";
                OdbcDataAdapter da = new OdbcDataAdapter(sql, Myconnection);
                da.Fill(ds, tablename); 
                //以上为建立连接,读取数据库并填充到dataset
                MessageBox.Show("ds:" + ds.Tables[tablename].Rows.Count.ToString());//运行显示为4
                MessageBox.Show(ds.Tables[tablename].Rows[3].RowState.ToString());//显示第4行状态为UnChanged
                ds.Tables[tablename].Rows[3].Delete();  //删除一行
                MessageBox.Show(ds.Tables[tablename].Rows[3].RowState.ToString());//现在显示为Deleted
                OdbcCommand cmddel = new OdbcCommand("Delete From Authority where authcode = @authcode", Myconnection);
                cmddel.Parameters.Add("@authcode", OdbcType.Int, 11, "authcode");
                da.DeleteCommand = cmddel;
                try
                {
                    int errNum = da.Update(ds, tablename);
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                }结果显示出错信息为Concurrency violation: the DeleteCommand affected 0 of the expected 1 records.不知道为什么会删除不成功……
      

  3.   

    OdbcCommand cmddel = new OdbcCommand("Delete From table1 where authcode = @authcode", Myconnection);
      

  4.   

    可义看一下这里的示例:
    http://blog.csdn.net/zhzuo/archive/2004/08/06/67016.aspx
    http://blog.csdn.net/zhzuo/archive/2004/08/06/67037.aspx
    http://blog.csdn.net/zhzuo/archive/2005/01/03/238273.aspx