Access 数据库有两个表--tab_a
id int identity(1,1),
uid  varchar(20),--用户ID;格式: 签证*******
city varchar(10)default('未知')--tab_b
dng varchar(10),--用户ID里的签证
city --地市
实现:为tab_a 表的,每个用户,设置地市
实现过程:tab_a 的uid的前10位 等于tab_b的dng。那么tab_a 的city 设置成 tab_b 的对应city
update tab_a inner join tab_b on tab_a.uid like tab_b.dng+'%%' set  tab_a.city=tab_b.city 
tab_a 有100多万,这个语句在Access中执行非常慢
////////////////////////////////////////////////////////
所以我想用
BackgroundWorker控件,显示进度//将tab_b表读出来
DataTable  dt_dngs=GetDngs();
            DataSet ds= new DataSet();
            DataTable dt = new DataTable();
            OleDbConnection con = new OleDbConnection("-------" );
           con.Open();
            OleDbCommand cmd = new OleDbCommand("select * from tab_a");
             OleDbDataAdapter da = new OleDbDataAdapter(cmd );
               // OleDbCommandBuilder ocb = new OleDbCommandBuilder(da );
             da.Fill(ds,"tab");
             dt=ds.Tables ["tab"];
             for(int i=0;i<dt.Rows.Count;i++)
             {
                    for(int j=0;j<dt_dngs.Rows.Count;j++)
                     {
                         if(dt_dngs[j]["dng"]==dt.Rows[i]["uid"].ToString().Substring(0,10) )
                         { dt.Rows[i]["city"]=dt_dngs[j]["city"];
                             breakl;
                          }
                     }
              }
             da.Update(ds,"tab");//一次性批量更新
 这样,总是报错:当传递具有已修改行的DataRow集合时,更新要求有效的UpdateCommand 

解决方案 »

  1.   

    for里面没有明白,你介绍下。
      

  2.   


                //遍历tab_A表数据
                for(int i=0;i<dt.Rows.Count;i++)
                 {
                        //遍历tab_B表数据                    for(int j=0;j<dt_dngs.Rows.Count;j++)
                         {
                              //如果 A表的 UID的前10个字符 等于B的DNG
                             if(dt_dngs[j]["dng"]==dt.Rows[i]["uid"].ToString ().Substring  (0,10) )
                             {//那么A 的City 等于 B表对应的地市
                                dt.Rows[i]["city"]=dt_dngs[j]["city"];
                                 break;
                              }
                         }
                  }
      

  3.   

    UpdateCommand  是否要有明文的UPDATE SQL语句的,
    另外,100W数据,建议用其它数据库,别用ACCESS了