i'm trying to write a C# application that reads data from one table of OleDb database to another table of OleDb database. The source and destination table will be decided during run time by the user.
The way i'm doing it right now is, reading everything into OleDbDataReader, iterating through each row and inserting into other table.
// create insert string
insert = "INSERT INTO " + Dest_Table + " VALUES (";
for(int i = 0; i < cols.Length; i++) // cols is array of column names
{
string coma = ", ";
if (i == cols.Length - 1)
coma = " )";
insert += "?" + coma;
}
// read each row and insert
while (src_reader.Read())
{
dstcmd.CommandText = insert;
for (int i = 0; i < cols.Length; i++)
{
string temp = "@" + cols[i];
dstcmd.Parameters.AddWithValue(temp, src_reader[cols[i]]);
// for debug purpose
Console.Write(temp + " " + src_reader[cols[i]] + "\n");
}
dstcmd.ExecuteNonQuery();
}
I was wondering, is there a better and more efficient way to do data transfer between tables of different databases? Or is it the only way? I know that in SqlConnection, there's a SqlBulkCopy method that can do this, but what about OleDbConnection? Is there something similar to SqlBulkCopy?
Any help will be appreciated. Thanks.