0

I have the following code:

OleDbConnection connection = new OleDbConnection(string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}; Extended Properties=""text;HDR=Yes;FMT=Delimited"";", Path.GetDirectoryName(ofd.FileName)));
OleDbCommand command = new OleDbCommand("SELECT * FROM " + Path.GetFileName(ofd.FileName), connection);
OleDbDataAdapter adapter = new OleDbDataAdapter(command);
Export_btn.Enabled = false;
Report_btn.Enabled = false;
Start_btn.Enabled = false;          
Start_btn.Text = "Loading CSV...";
adapter.Fill(dt); 

And this csv:

enter image description here

But it return an import error showing that the epc column need int32 type. And the expection = System.ArgumentException How can I fix it?

Mukesh Ram
  • 6,248
  • 4
  • 19
  • 37
Wai Hung
  • 49
  • 10
  • Take a look here: https://msdn.microsoft.com/en-us/library/system.io.path.getfilename(v=vs.110).aspx `Path.GetFileName()` – Niklas Sep 23 '16 at 03:55

2 Answers2

0

check datatable strcture dt . In csv file, epc column contain alphanumeric value so in datatable dt , column epc should be string type.

0

you need to give Schema.ini file to specify datatype of column in csv file More info can be found on MSDN https://msdn.microsoft.com/en-us/library/ms709353(v=vs.85).aspx

below is example of Schema.ini file.

[YourCSVFileName.csv]
ColNameHeader=True
Format=CSVDelimited
MaxScanRows=0
DateTimeFormat=dd-MMM-yyyy
Col1=A DateTime
Col2=B Text Width 100
Col3=C Text Width 100
Col4=D Long
Col5=E Double