问题描述
我在程序中建立了一个datatabledt1.。里边有一些数据。。。在数据库中有一个表demo...dt1和demo的结构都是一样的。。我现在想把dt1复制到demo表中。。。我不想一条条的插入到demo中。。这样太消耗服务器有没有办法。。把dt1整个复制进demo中呢
解决方案
解决方案二:
使用OleDbDataAdapter+DataSet可以批量更新数据publicDataSetCreateCmdsAndUpdate(DataSetmyDataSet,stringmyConnection,stringmySelectQuery,stringmyTableName){OleDbConnectionmyConn=newOleDbConnection(myConnection);OleDbDataAdaptermyDataAdapter=newOleDbDataAdapter();myDataAdapter.SelectCommand=newOleDbCommand(mySelectQuery,myConn);OleDbCommandBuildercustCB=newOleDbCommandBuilder(myDataAdapter);myConn.Open();DataSetcustDS=newDataSet();myDataAdapter.Fill(custDS);//codetomodifydataindatasetheremyDataAdapter.Update(custDS,myTableName);myConn.Close();returncustDS;}
解决方案三:
使用OleDbDataAdapter+DataSet可以批量更新数据publicDataSetCreateCmdsAndUpdate(DataSetmyDataSet,stringmyConnection,stringmySelectQuery,stringmyTableName){OleDbConnectionmyConn=newOleDbConnection(myConnection);OleDbDataAdaptermyDataAdapter=newOleDbDataAdapter();myDataAdapter.SelectCommand=newOleDbCommand(mySelectQuery,myConn);OleDbCommandBuildercustCB=newOleDbCommandBuilder(myDataAdapter);myConn.Open();DataSetcustDS=newDataSet();myDataAdapter.Fill(custDS);//codetomodifydataindatasetheremyDataAdapter.Update(custDS,myTableName);myConn.Close();returncustDS;}