Excel into DataTable using OleDbDataAdapter

M

Matthew_H

Query fails to fetch Excel data formatted as currency. How can I get
currency data from Excel into a .NET DataSet. This query works fine for all
other Excel Data fields!

Thank you for your help.


//===========================
string xlsFile = fullFilePathStr;
DataSet importDS = new DataSet();
OleDbConnection objConn = null;
System.Data.DataTable dt = null;
string connString;
connString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + xlsFile + ";" +
"Extended Properties=Excel 8.0;";
objConn = new OleDbConnection(connString);

// Open connection with the database.
objConn.Open();

// Get the data table containg the schema guid.
dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
try
{
OleDbDataAdapter myCommand = new OleDbDataAdapter( " SELECT * FROM ["
+worksheetNameStr+ "$] ", objConn);
myCommand.AcceptChangesDuringFill=true;
importDS.EnforceConstraints=false;
myCommand.Fill(importDS);
}
catch(Exception ex)
{
string exStr = ex.ToString();
}

finally
{
if(objConn != null)
{
objConn.Close();
objConn.Dispose();
}
if(dt != null)
{
dt.Dispose();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top