我有一个SQL Server表,包含大约20000多行数据,同样我必须插入到运行时创建的sqlite数据库中。请建议哪种方法是导入数据的最佳方法?
我有两组代码:
DataTable table = new DataTable();
using (var con = new SqlConnection(classlayer.SQLconnectionstring))
using (var cmd = new SqlCommand(spname, con))
using (var da = new SqlDataAdapter(cmd))
{
da.AcceptChangesDuringFill = false;
cmd.CommandType = CommandType.StoredProcedure;
da.Fill(table);
}
string qry = "Select * from " + tablename;
var sqliteAdapter = new SQLiteDataAdapter(qry, sqlitecon);
var cmdBuilder = new SQLiteCommandBuilder(sqliteAdapter);
sqliteAdapter.Update(table);
或者这个
string MyConString = "SERVER=SERVER;DATABASE=mydb;User ID=sa;Password=password;";
string query = "";
SqlConnection connection = new SqlConnection(MyConString);
SqlCommand command = new SqlCommand("select Code,Name,route from Localities", connection);
SqlDataReader Reader;
SQLiteConnection conn = new SQLiteConnection("Data Source=W:\\Localities.db;Version=3;");
connection.Open();
conn.Open();
Reader = command.ExecuteReader();
int i = 0;
while (Reader.Read())
{
query = "Insert into Localities(Code,Name,route) values('" + Reader.GetValue(0).ToString() + "','" + Reader.GetValue(1).ToString() + "','" + Reader.GetValue(2).ToString() + "')";
SQLiteCommand cmd = new SQLiteCommand(query, conn);
i = i + cmd.ExecuteNonQuery();
}