日期:2014-05-17  浏览次数:21006 次

急!如何将DataSet的数据批量插入到Access?
DataSet内有一个数据量很大的表,如何把它一次性插入到Access中?

------解决方案--------------------
借鉴下别人的代码吧。
C# code

try 
{ 
oracleConnection1.Open(); 
System.Data.OracleClient.OracleDataAdapter   ora_adp   =   new   System.Data.OracleClient.OracleDataAdapter( "select   *   from   clientregiste ",oracleConnection1); 
  OracleCommandBuilder   objCommandBuilder= 
new   System.Data.OracleClient.OracleCommandBuilder(ora_adp); 
ora_adp   .DeleteCommand   =   objCommandBuilder.GetDeleteCommand(); 
ora_adp   .InsertCommand   =   objCommandBuilder.GetInsertCommand();//如果只是删除操作后更新, 
此句和下面一句可以不要 
ora_adp   .UpdateCommand   =   objCommandBuilder.GetUpdateCommand();// 

DataSet   dstobj   =   new   DataSet(); 
ora_adp.Fill(dstobj, "originally "); 
System.Data.DataRow   row   =   dstobj.Tables[ "originally "].Rows[1]; 
row.Delete(); 
dstobj.AcceptChanges(); 
ora_adp.Update(dstobj, "originally "); 
oracleConnection1.Close(); 
} 
catch(Exception   ora_err) 
{ 
Label1.Text   =   ora_err.Message; 
} 
finally 
{ 
oracleConnection1.Close(); 
}

------解决方案--------------------
试试下面的,再不行的话就得用常规办法了.
 Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Test Files\db1 XP.mdb")

AccessConn.Open()

'New table
Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT * INTO [tbl1] FROM [Text;DATABASE=C:\Documents and Settings\...\My Documents\My Database\Text].[tbl1.txt]", AccessConn)
'Existing table
'Dim AccessCommand As New System.Data.OleDb.OleDbCommand("INSERT INTO [tbl1] (F1, F2, F3) SELECT F1, F2, F3 FROM [Text;DATABASE=C:\Documents and Settings\...\My Documents\My Database\Text].[tbl1.txt]", AccessConn)

AccessCommand.ExecuteNonQuery()
AccessConn.Close()
 The schema.ini file would look something like following:

[tbl1.txt]
ColNameHeader=False
Format=TabDelimited
CharacterSet=ANSI