Problem in loading Excel file.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alpha Zero

    #1

    Problem in loading Excel file.

    Hi!
    I am making connection to excel.
    But all fields which are not of string type are being read as null.
    ---------------code-------------------------------
    excelConnection = new System.Data.Ole Db.OleDbConnect ion(
    @"provider=Micr osoft.Jet.OLEDB .4.0;data source="+file+" ; Extended
    Properties=\"Ex cel 8.0;HDR=No\"");

    excelConnection .Open();

    //Guid guid = new Guid();

    System.Data.Dat aTable schema =
    excelConnection .GetOleDbSchema Table(System.Da ta.OleDb.OleDbS chemaGuid.Table s
    ,null);


    string firstSheetName;

    firstSheetName = schema.Rows[0]["TABLE_NAME "].ToString();

    excelCommand = new System.Data.Ole Db.OleDbCommand ( "select * from
    ["+firstSheetNam e+"A:AL]", excelConnection );

    excelCommand.Co mmandType = CommandType.Tex t;


    excelDa = new OleDbDataAdapte r(excelCommand) ;

    excelDs = new System.Data.Dat aSet();

    excelDa.Fill(ex celDs);

    excelFileTable = excelDs.Tables[0];

    DataRow dataRow;

    dataRow = excelFileTable. Rows[i];

    ---------------code-------------------------------

    All elemetns of dataRow which are not string are null.

    Any Idea?

    Thanks.










Working...