方法一

DataTable table = new DataTable();
            //TODO: init table...
            string connStr = "user  + dbInfo.Password;
            SqlConnection conn = new SqlConnection(connStr);
            conn.Open();
            SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(conn);
            sqlBulkCopy.DestinationTableName = dbInfo.TableName;
            sqlBulkCopy.WriteToServer(table);
            sqlBulkCopy.Close();

方法二

DataTable table = new DataTable();
            //TODO: init table...

            string connStr = "user  + dbInfo.Password;
            DataTable dt = new DataTable();
            SqlConnection conn = new SqlConnection(connStr);
            SqlCommand cmd = new SqlCommand(string.Format("select * from {0} where 1=2", dbInfo.TableName), conn);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            SqlCommandBuilder Builder = new SqlCommandBuilder(sda);
            sda.Fill(dt);

            DataRow addRow = null;
            foreach (DataRow row in table.Rows)
            {
                addRow = dt.NewRow();
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    addRow[i] = row[i];
                }
                dt.Rows.Add(addRow);
            }

            sda.Update(dt);


总结

1. 仅仅有 Insert ? 那么用 SqlBulkCopy.
2. Insert/Update/Delete ? 那么用 DataAdapter.Update.


相关文章:

  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-01
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2022-02-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案