Here I will show how to Import data from csv file to sql database or any other database.
//This is the connection string to connect to your csv file
string strConString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\; Extended Properties=\”Text;HDR=YES;\”";
// open connection
OleDbConnection oCon = new OleDbConnection(strConString);
oCon.Open();
// fill data set
string strSql = “SELECT * FROM csvfile.csv”; //csvfile should be present in c:
OleDbDataAdapter oDA = new OleDbDataAdapter(strSql, oCon);
DataSet oData = new DataSet();
oDA.Fill(oData, “ABC”);
GridView1.DataSource = oData;
GridView1.DataBind();
oCon.Close();
Filed under: asp.net c#, csv, sql | Tagged: c#, csv, csv to sql, dot net, get csv, import csv file to database, import csv to sql, read csv file, sql



Any idea on how to specify a character set. I have an implmentation of this, but it has come to light that certain characters are not being read into the dataset set correctly.
For example äüö is changed to äüö .
Does anyone have any ideas, it there an additional parameter for the connection string or a property for the oleadapter for example that I am missing?
Cheers.
Hi rohitsies ,
you really helped me out here. I spend quite some time to get a csv file into a dataset, but didn’t know the exact configuration.
tnx a lot for your post!!
Frank
(the Netherlands)
You’re Welcome anytime!
hello rohitsies,
Thanks for such a nice dataset example,
It really halped me.
Thanks
I’m ready to help you Always!
Hi rohitsies,
Thank you very much for your example. It helped me a lot.
Regards,
Thant Zin