Problem in uploading Date from Excel

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ramakrishnan Nagarajan

    #1

    Problem in uploading Date from Excel

    Hi,
    I am facing a problem in uploading Excel data to the Database. While
    uploading my code reads Excel Data using OleDbReader and store into a dataset
    by looping through the OleDbReader result set. The problem is, if I give the
    date as mm/dd/yyyy format it accepts, but when I give the date in dd/mm/yyyy
    format, upto 8 rows of data it is reporting the date as invalid. After 8th
    row even if the date is there (dd/mm/yyyy format), it is reporting like Date
    field is blank (the OleDbReader itself is reading the date as blank.) I am in
    a crucial situation to get a solution for this problem. Can anyone please
    help me.
    Thank You,
    Regards,
    N.Ramakrishnan

    //Following is the Code I use to read Excel Data using OleDbReader


    string prop = "\"Excel 8.0;IMEX=1;HDR= YES\"";
    string strConn = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=";
    strConn = strConn + filePath + ";";
    strConn = strConn + "Extended Properties=";
    strConn = strConn + prop;

    OleDbConnection xlCon = new OleDbConnection (strConn);

    xlCon.Open();

    string selStmt = "SELECT * FROM [" + sheetName + "]";
    OleDbCommand xlCmd = new OleDbCommand(se lStmt, xlCon);
    xlCmd.CommandTy pe = CommandType.Tex t;
    OleDbDataReader xlReader = xlCmd.ExecuteRe ader();
    //Create a structure for the dataset
    for(short fldIndex = 0; fldIndex < xlReader.FieldC ount; fldIndex++)
    {
    xlDataSet.Table s[0].Columns.Add(ne w DataColumn(xlRe ader.GetName(fl dIndex),
    Type.GetType("S ystem.String")) );
    }


    DataRow dRow;
    while(xlReader. Read())
    {
    dRow = xlDataSet.Table s[0].NewRow();
    for(short fldIndex = 0; fldIndex < xlReader.FieldC ount; fldIndex++)
    {
    dRow[fldIndex] = Convert.ToStrin g(xlReader[fldIndex]);
    }
    xlDataSet.Table s[0].Rows.Add(dRow) ;
    }
    xlReader.Close( );
Working...