c# - Issue with importing .csv using MS Jet OLEDB -


i'm importing csv file sql asp .net application. able import .csv, 1 column contains null values if there other numbers in it.

this row imports fine:

1109,003,in,0093219095,3/17/2013,3/21/2013,,sobeys warehouse,4819.13,61.37,4880.50,rv,1109-003 

the fourth column null in sql:

1109,999,in,ref 44308/s. dra,3/18/2013,3/21/2013,,"ec rebates w/e -02 14, 2013",-200.02,0.00,-200.02,sa,1109-999 

all other columns have text in them import fine, fourth 1 issue. can't figure out possibly different affected column on others. if replace text numbers imports text data. sql field nvarchar(50) not datatype issue.

my connection string (dir contains path folder):

string connstring = "provider=microsoft.jet.oledb.4.0;data source=\"" + dir + "\\\";extended properties='text;hdr=yes;fmt=delimited(,)';"; 

import code:

    public datatable getcsv(string path)     {         if (!file.exists(path))         {             return null;         }          datatable dt = new datatable();         string fullpath = path.getfullpath(path);         string file = path.getfilename(fullpath);         string dir = path.getdirectoryname(fullpath);         string connstring = "provider=microsoft.jet.oledb.4.0;data source=\"" + dir + "\\\";extended properties='text;hdr=yes;fmt=delimited(,)';";         string query = "select * " + file;         system.data.oledb.oledbdataadapter da = new system.data.oledb.oledbdataadapter(query, connstring);          try         {             da.fill(dt);         }         catch (invalidoperationexception)         {         }          da.dispose();          return dt;     } 

this solved issue. pondlife getting me pointed in right direction. figured had data types, not sure getting walloped.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms709353%28v=vs.85%29.aspx


Comments