string file = FileUpload1.PostedFile.FileName; file = Path.GetFileName(file); string filepath = Server.MapPath("~/csv/")+file; FileUpload1.SaveAs(filepath); StreamReader sr = new StreamReader(filepath); string line = sr.ReadLine(); 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); } } string sql = "Insert into company(CompanyName,ContactPerson,Email,Tel,Address,DemurrageOffrered)values(@CompanyName,@ContactPerson,@Email,@Tel,@Address,@DemurrageOffered)"; sc.Open(); foreach (DataRow r in dt.Rows) { MySqlCommand cmd = sc.CreateCommand(); cmd.CommandText = sql; cmd.Parameters.AddWithValue("@CompanyName", r["CompanyName"]); cmd.Parameters.AddWithValue("@ContactPerson", r["ContactPerson"]); cmd.Parameters.AddWithValue("@Email", r["Email"]); cmd.Parameters.AddWithValue("@Tel", r["Tel"]); cmd.Parameters.AddWithValue("@Address", r["Address"]); cmd.Parameters.AddWithValue("@DemurrageOffered", r["DemurrageOffered"]); } sc.Close(); Response.Write("ook");
System.Data.SqlClient.SqlCommand.ExecuteNonQuery
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)