Problem Retrieving From Excel in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xia0jie
    New Member
    • Oct 2009
    • 1

    Problem Retrieving From Excel in C#

    Hi all, Im using the following codes to retrieve records from excel file.

    OleDbConnection conn = new OleDbConnection (@"Provider=Mic rosoft.Jet.OLED B.4.0; Data Source=" + Path + "; Extended Properties='Exc el 8.0;HDR=Yes;IME X=1'");

    OleDbCommand cmd = new OleDbCommand("S ELECT TOP 10 * FROM [Sheet1$] WHERE [Project] <> ''", conn);

    DataSet ds = new DataSet();
    da = new OleDbDataAdapte r(cmd);
    da.Fill(ds);

    DataTable table = ds.Tables[0];

    In the excel file, there's a column storing values such as "IRAS 2009", "Nov-07" etc. When i retrieve from the DataTable it return me NULL and "31-Nov-07" respectively.

    Why is it so? Why im unable to get the exact value and those in the excel file? Any help is greatly appreciated.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    I'm unsure about why "IRAS 2009" goes to NULL, but I'm pretty sure the date is a formatting thing. If it's an actual date in excel, then yea, your data table is just giving you a different format, but it's still the same date.

    You can either change it to a string in excel, or format the date on output differently. The latter would probably be the better choice ;)

    Comment

    Working...