for a small project I need to create a DataTable filled with data from an Excelsheet. Im getting this data with using an Oledb connection. Sometimes other people are using this file on the server. Is there any way with completing this with Oledb?
private DataTable excelSelectStatement() {
try {
string par = this._colParameters.getParameterByName("SheetName", false, null).Value;
excelDataSet = new DataSet();
string ace12 = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + _selectionStatement + "';Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';";
using (OleDbConnection connection = new OleDbConnection(ace12)) {
OleDbDataAdapter da = new OleDbDataAdapter("select * from [" + par + "$]", connection);
da.TableMappings.Add("Table", "TestTable");
da.Fill(excelDataSet);
}
}
catch (Exception e) { MessageBox.Show(e.Message); }
return excelDataSet.Tables[0];
}
Aucun commentaire:
Enregistrer un commentaire