hi,
how to import csv file to DataGrid. please give a sample code.
Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sanjeeb LenkaPosted Jul 10, 2013, 2:42 AM
http://www.c-sharpcorner.com/uploadfile/ankurmee/import-data-from-text-and-csv-file-to-datagridview-in-net/
Rasadul Alam RashedPosted Jul 10, 2013, 2:38 AM
Code is here :http://cybarlab.blogspot.com/2013/03/import-csv-file-into-database-in-c.html
Dorababu MekaPosted Sep 8, 2010, 7:53 AM
private void loadcsv()
{
string delimitter = ",";
string tablename = "Tblname";
string filename = "c:\\xyz.csv";
DataSet ds = new DataSet();
StreamReader sr = new StreamReader(filename);
ds.Tables.Add(tablename);
ds.Tables[tablename].Columns.Add("Product"); //What ever fields you have in csv add here
ds.Tables[tablename].Columns.Add("Price");
string srread = sr.ReadToEnd();
string[] rows = srread.Split("\r".ToCharArray());
foreach (String str in rows)
{
string[] items = str.Split(delimitter.ToCharArray());
ds.Tables[tablename].Rows.Add(items);
}
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}