Below is my code to convert a csv file into DataTabel.
public static DataTable ImportCSVtoDatatable(string filepath, string strQuery )
{
//strQuery = "Select * From [GJ20150417044150]";
//string filepath= @"h$\\Data\\GJ20150417044150.csv";
DataSet ds = new DataSet();
var constring = string.Format(@"Provider=Microsoft.Jet.OleDb.4.0; Data Source={0};Extended Properties=""Text;HDR=YES;FMT=Delimited""", Path.GetDirectoryName(filepath));
OleDbConnection con = new OleDbConnection(constring);
OleDbDataAdapter da = new OleDbDataAdapter(strQuery, con);
//Error Occuring on this step
da.Fill(ds);
DataTable dt = ds.Tables[0];
return dt;
}
my program got crashed and the error I am getting is as follows:
The Microsoft Jet database engine could not find the object 'GJ20150417044150.txt'. Make sure the object exists and that you spell its name and the path name correctly.
what I guess is ,it's trying to search for "GJ20150417044150.txt" file but could not get it as it is actually "GJ20150417044150.csv" file and there is no "GJ20150417044150.txt" in the given path.
please help me in:
1: How to get rid of this error and select the desired .csv file to convert into datatable.
2: Why this .txt is Added to the GJ20150417044150 in the process