private static SqlDataAdapter GetAdapter(string sql, SqlParameter[] parameters) { DALSql dal = GetThreadDal(); dal.CheckConnection(); SqlCommand sc = new SqlCommand(sql, dal.Connection); sc.CommandType = CommandType.Text; sc.CommandTimeout = 0; if (parameters != null) { sc.Parameters.AddRange(parameters); } foreach (SqlParameter parameter in sc.Parameters) { if (parameter.Value == null) { parameter.Value = DBNull.Value; } if (parameter.SqlDbType == SqlDbType.DateTime && parameter.Value.Equals(new DateTime(1, 1, 1))) { parameter.Value = DBNull.Value; } } return(new SqlDataAdapter(sc)); }
public static void BulkCopy(string tableName, DataTable insertData) { DALSql dal = GetThreadDal(); dal.CheckConnection(); SqlBulkCopy bulkCopy = new SqlBulkCopy(dal.Connection); bulkCopy.DestinationTableName = tableName; foreach (DataColumn dc in insertData.Columns) { bulkCopy.ColumnMappings.Add(dc.ColumnName, dc.ColumnName); } bulkCopy.WriteToServer(insertData); }
public static void AddEventText(Action <string> act) { DALSql dal = GetThreadDal(); dal.CheckConnection(); if (dal.EventText != null) { dal.Connection.InfoMessage -= dal.EventText; } dal.EventText = new SqlInfoMessageEventHandler( (sender, e) => { act(e.Message); }); dal.Connection.InfoMessage += dal.EventText; }