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();
Advertisement
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.
Comment by Tina — July 29, 2008 @ 2:51 pm
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)
Comment by Frank — August 3, 2008 @ 8:01 pm
You’re Welcome anytime!
Comment by rohitsies — December 8, 2008 @ 12:15 pm
hello rohitsies,
Thanks for such a nice dataset example,
It really halped me.
Thanks
Comment by shreya — December 9, 2008 @ 8:07 am
I’m ready to help you Always!
Comment by rohitsies — December 9, 2008 @ 9:11 am
Hi rohitsies,
Thank you very much for your example. It helped me a lot.
Regards,
Thant Zin
Comment by Thant Zin — December 17, 2008 @ 4:34 am