J
James
Hi,
I'm importing some csv files with this code
/// start of code snippet
int iPos = strFileName.LastIndexOf(@"\");
string strPath = strFileName.Substring(0,iPos);
string strSelect = "Select * from [" + strFileName.Substring(iPos+1) + "]";
string strConnection;
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
strConnection += strPath;
strConnection += ";Extended Properties='text;HDR=No;FMT=Delimited'";
System.Data.OleDb.OleDbConnection CSVConnection = new
System.Data.OleDb.OleDbConnection(strConnection);
CSVConnection.Open();
System.Data.OleDb.OleDbDataAdapter CSVAdapter = new
System.Data.OleDb.OleDbDataAdapter(strSelect, CSVConnection);
DataSet CSVDataset = new DataSet("CSVFile");
CSVAdapter.Fill(CSVDataset, "CSVFile");
CSVConnection.Close();
DataTable CSVDatatable;
CSVDatatable = CSVDataset.Tables["CSVFile"];
/// end of code snippet
I have found that only files with a .csv extension can be opened otherwise I
get an exception that read 'Cannot Update, Database or Object is read-only'.
Is that normal and is there a way around it?
Also, since I'm using the Microsoft.Jet.OLEDB.4.0 provider will the users
machine need to have Access or Office installed in order for this to work?
Finally, should I be using another provider, just wondering since I took
most of it from a sample code.
Thank you for your time.
I'm importing some csv files with this code
/// start of code snippet
int iPos = strFileName.LastIndexOf(@"\");
string strPath = strFileName.Substring(0,iPos);
string strSelect = "Select * from [" + strFileName.Substring(iPos+1) + "]";
string strConnection;
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
strConnection += strPath;
strConnection += ";Extended Properties='text;HDR=No;FMT=Delimited'";
System.Data.OleDb.OleDbConnection CSVConnection = new
System.Data.OleDb.OleDbConnection(strConnection);
CSVConnection.Open();
System.Data.OleDb.OleDbDataAdapter CSVAdapter = new
System.Data.OleDb.OleDbDataAdapter(strSelect, CSVConnection);
DataSet CSVDataset = new DataSet("CSVFile");
CSVAdapter.Fill(CSVDataset, "CSVFile");
CSVConnection.Close();
DataTable CSVDatatable;
CSVDatatable = CSVDataset.Tables["CSVFile"];
/// end of code snippet
I have found that only files with a .csv extension can be opened otherwise I
get an exception that read 'Cannot Update, Database or Object is read-only'.
Is that normal and is there a way around it?
Also, since I'm using the Microsoft.Jet.OLEDB.4.0 provider will the users
machine need to have Access or Office installed in order for this to work?
Finally, should I be using another provider, just wondering since I took
most of it from a sample code.
Thank you for your time.