C#批量入库
public static void BulkCopyToDB(DataTable dt, string conn, string tableName, out string msg) { msg = ""; if (dt.Rows.Count > 0) { using (SqlConnection connection = new SqlConnection(conn)) { connection.Open(); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection)) { bulkCopy.DestinationTableName = tableName; try { bulkCopy.WriteToServer(dt); } catch (Exception ex) { msg = ex.Message.ToString(); BLL.Loger.Log4Net.Error(ex.Message, ex); } finally { bulkCopy.Close(); } } } } }