C# 将数据批量插入accesss中

来源:互联网 发布:java调用ie浏览器 编辑:程序博客网 时间:2024/05/16 14:45
   public static DataTable UpdateRows(string connectionString, string queryString, string tableName, DataSet ds)        {            using (OleDbConnection conn = new OleDbConnection(connectionString))            {                conn.Open();                OleDbDataAdapter adapter = new OleDbDataAdapter(queryString, conn);                OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);                DataTable table1 = new DataTable();                adapter.Fill(table1);                for (int n= 0; n< ds.Tables[0].Rows.Count; n++)                {                    DataRow row = table1.NewRow();                    for (int m = 0; m < ds.Tables[0].Columns.Count; m++)                    {                        row[m+1] = ds.Tables[0].Rows[n][m].ToString();                                           }                    table1.Rows.Add(row);                }                adapter.UpdateCommand = builder.GetUpdateCommand();                adapter.Update(table1);                return table1;            }        }

因为我不知道datatable的列和行数所以就用了循环;

access中的批量更新语句,也就是在sqlserver内的语句是update t1 set t1.id = t2.id from t2 where t1.id1 = t2.id1;的功能在access内的语句:

UPDATE [t1] as a INNER JOIN [t2] as b ON a.电话 = b.号码 SET  a.状态1 =b.状态

0 0