+ Reply to Thread
Results 1 to 2 of 2

Excel into DataTable using OleDbDataAdapter

  1. #1
    Matthew_H
    Guest

    Excel into DataTable using OleDbDataAdapter

    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();
    }
    }

  2. #2
    Jamie Collins
    Guest

    Re: Excel into DataTable using OleDbDataAdapter

    Matthew_H wrote:
    > Query fails to fetch Excel data formatted as currency. How can I get


    > currency data from Excel


    First, ensure your data actually is of type Currency. Formatting is a
    factor but no guarantee e.g. Text in a column with a currency format is
    still Text. Ensure you do not have a mixed types situation - see:

    http://www.*****-blog.com/archives/2...ed-data-types/

    Jamie.

    --


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1