public static void BulkUpdate(string col, System.IO.StreamReader sr, string tableName) { ConnStr = ConfigurationSettings.AppSettings["ConnStrAffiliate"].Trim(); SqlConnection myConn = DAO.fetchConnection(); //string line = sr.ReadLine(); string[] value = col.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); DataTable dt = new DataTable(); DataRow row; foreach (string dc in value) { dt.Columns.Add(new DataColumn(dc, typeof(string))); } while (!sr.EndOfStream) { value = sr.ReadLine().Split(new char[] { '\t' }); List<string> valueList = value.ToList(); valueList.RemoveAt(valueList.Count - 1); value = valueList.ToArray(); if (value.Length == dt.Columns.Count) { row = dt.NewRow(); row.ItemArray = value; dt.Rows.Add(row); } } SqlBulkCopy bc = new SqlBulkCopy(ConnStr, SqlBulkCopyOptions.TableLock); bc.DestinationTableName = tableName; bc.BatchSize = dt.Rows.Count; bc.WriteToServer(dt); bc.Close(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)