对于2个数据集ds_imp,ds_exp,ds_imp,和ds_exp中的表结构完全一样,首先检查在ds_exp中是否有ds_imp有重复记录,如有,删除ds_exp中重复的数据,然后将ds_imp中的 数据全部导入ds_exp 中,代码入下:
string  tb_name;

   tb_name=inlistBox.Items[x].ToString();
               string impsql="select * from "+tb_name+""; 
   string expsql="select * from "+tb_name+"";
               DataSet  ds_exp=new DataSet();
OleDbDataAdapter  mydata =new OleDbDataAdapter(expsql,myConn1);
mydata.Fill(ds_exp);
// OleDbCommandBuilder builderl=new OleDbCommandBuilder(mydata);

OleDbDataAdapter myCom = new OleDbDataAdapter ( impsql,myConn ) ;
DataSet  ds_imp=new DataSet();
myCom.Fill(ds_imp);
// OleDbCommandBuilder builder=new OleDbCommandBuilder(myCom);

if (ds_imp.Tables[0].Rows.Count!=0) {
string unitid=ds_imp.Tables[0].Rows[0]["UNITID"].ToString();
DataRow [] temp =ds_exp.Tables[0].Select("UNITID='" +unitid+"'");
if (temp.Length!=0) {

string deletesql="delete * from "+tb_name+" where UNITID='" +unitid+"'";
OleDbCommand cmdCommand = new OleDbCommand(deletesql,myConn1);
cmdCommand.ExecuteNonQuery();
DataSet  ds_exp1=new DataSet();
OleDbDataAdapter  mydata1 =new OleDbDataAdapter(expsql,myConn1);
OleDbCommandBuilder builderl=new OleDbCommandBuilder(mydata1);
mydata1.Fill(ds_exp1);
                           

for(int s=0;s<ds_imp.Tables[0].Rows.Count;s++)
{
//在这里不能使用ImportRow方法将一行导入到news中,因为ImportRow将保留原来DataRow的所有设置(DataRowState状态不变)。在使用ImportRow后newds内有值,但不能更新到Excel中因为所有导入行的DataRowState!=Added
DataRow nrow=ds_exp1.Tables[0].NewRow();
// MessageBox.Show( newds.Tables[0].Columns.Count.ToString());
for(int n=0;n<ds_exp1.Tables[0].Columns.Count;n++)
{
nrow[n]=ds_imp.Tables[0].Rows[s][n];
}
{
ds_exp1.Tables[0].Rows.Add(nrow);
}
}
mydata.Update(ds_exp1,tb_name);

}
else
{
for(int g=ds_exp.Tables[0].Rows.Count;g<ds_imp.Tables[0].Rows.Count+ds_exp.Tables[0].Rows.Count;g++)
{
//在这里不能使用ImportRow方法将一行导入到news中,因为ImportRow将保留原来DataRow的所有设置(DataRowState状态不变)。在使用ImportRow后newds内有值,但不能更新到Excel中因为所有导入行的DataRowState!=Added
DataRow nrow=ds_exp.Tables[0].NewRow();
// MessageBox.Show( newds.Tables[0].Columns.Count.ToString());
for(int p=0;p<ds_exp.Tables[0].Columns.Count;p++)
{
nrow[p]=ds_imp.Tables[0].Rows[g][p];
}
ds_exp.Tables[0].Rows.Add(nrow);
}
mydata .Update(ds_exp,tb_name);

}错误:不能update,当ds_exp中数据为空是,可以update,当ds_exp中有数据的时候,不能update.请将代码写出,各位大哥帮忙啊!!!!!!!!!如上代码不行,请将你知道能实现上面所说功能代码写出来.