public void ImportAllFilesOfFolder()//function declares methods to import// { try { using (StreamReader sr = new StreamReader(@"path of file")) { //StreamReader sr = new StreamReader(@"C:\Users\Priya\Desktop\B\b.csv"); string line = sr.ReadLine(); // line = line.Replace(",", ""); string[] value = line.Split(','); DataTable dt = new DataTable(); DataRow row; foreach (string dc in value) { dt.Columns.Add(new DataColumn(dc)); } while (!sr.EndOfStream) { value = sr.ReadLine().Split(','); if (value.Length == dt.Columns.Count) { row = dt.NewRow(); row.ItemArray = value; dt.Rows.Add(row); } } SqlBulkCopy bc = new SqlBulkCopy(con.ConnectionString, SqlBulkCopyOptions.TableLock); bc.DestinationTableName = "SaiHp"; bc.BatchSize = dt.Rows.Count; bc.WriteToServer(dt); bc.Close(); } } catch { } finally { con.Close(); } }
line.Split(',')
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)