日期:2014-05-18  浏览次数:20780 次

2 个表 如何更新数据
我使用  

OleDbDataAdapter   的   Fill   把2个表的数据写入呢一个DataSet的2个表内...2个表的列不一样

可是我在用   OleDbDataAdapter     的updata   更新   表1   的时候..

却提示我找不到表2   中的列.......


可是我在用   OleDbDataAdapter     的updata   更新   表2   的时候..

却提示我找不到表1   中的列.......


下面附上我的完整代码.....大家帮我看下.


DataSet   theDataSet   =   new   DataSet();
                        OleDbConnection   thisConnection   =   new   OleDbConnection(@ "Provider=Microsoft.Jet.OLEDB.4.0;Data   Source=D:\config2.mdb ");
                        OleDbDataAdapter   thisAdapter   =   new   OleDbDataAdapter();

                        //读入第一个表
                        thisAdapter.SelectCommand   =   new   OleDbCommand( "select   *   from   表1 ",   thisConnection);
                        thisAdapter.Fill(theDataSet,   "表1 ");
                        OleDbCommandBuilder   siteCommandBuilder   =   new   OleDbCommandBuilder(thisAdapter);

                        //写入第二个表
                        thisAdapter.SelectCommand   =   new   OleDbCommand( "select   *   from   表2 ",   thisConnection);
                        thisAdapter.Fill(theDataSet,   "表2 ");

                        OleDbCommandBuilder   thisCommandBuilder   =   new   OleDbCommandBuilder(thisAdapter);

                        foreach   (DataRow   theRow   in   theDataSet.Tables[ "表1 "].Rows)
                        {
                                theRow[2]   =   "新数据 ";
                        }
                        //修改第一个表
                        thisAdapter.Update(theDataSet,   "表1 ");


                        foreach   (DataRow   theRow   in   theDataSet.Tables[ "表2 "].Rows)
                        {
                                theRow[2]   =   "新数据 ";
                        }