先在mssql里查询出20条记录,然后插入Access里?
先在mssql里查询出20条记录,然后插入Access里?
[解决办法]
类似这样,已经过测试,字段名、路径等等自己修改一下。代码可以进一步完善。
using (SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=123456;database=test;"))
{
SqlDataAdapter sda = new SqlDataAdapter("select * from t1", conn);
DataTable dt = new DataTable();
sda.Fill(dt);
using (OleDbConnection oleConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "se.mdb;"))
{
oleConn.Open();
foreach (DataRow dr in dt.Rows)
{
string sql = "insert into t2 values('" + dr[0] + "')";
OleDbCommand cmd = new OleDbCommand(sql, oleConn);
cmd.ExecuteNonQuery();
}
}
}