i = 0; fil="Desktop"; string line=string.Empty; StreamReader sr = new StreamReader(filepath); line = sr.ReadLine(); line = sr.ReadLine(); string[] value = line.Split(','); DataTable dt = new DataTable(); DataRow row; i=0; foreach (string dc in value) { if (i == 0) { dt.Columns.Add(new DataColumn(fil)); // dt.Columns.Add(new DataColumn(DateTime.Now.ToString())); dt.Columns.Add(new DataColumn(dc)); i++; } } string value1; while ( !sr.EndOfStream ) { value1 = sr.ReadLine().Split(',')[0]; value = new string[] { value1 }; dt.Columns.Add(new DataColumn(value1)); if(value.Length == (dt.Columns.Count)-3) { row = dt.NewRow(); row.ItemArray = value; dt.Rows.Add(row); } } SqlBulkCopy bc = new SqlBulkCopy(con.ConnectionString, SqlBulkCopyOptions.TableLock); bc.DestinationTableName = "mssp_eps_compliance_report"; bc.BatchSize = dt.Rows.Count; con.Open(); bc.WriteToServer(dt); bc.Close(); con.Close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)