Results 1 to 8 of 8

Thread: Read Excel File + C#

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Read Excel File + C#

    I have excel file.I want to fill dataset from that excel file & Have to fill the database. I m able to read the excel file,but there is one problem with column whose datatype is Date.

    Code:
    Actual Payment Date
    12/15/2009
    If I have the above date, means first number is 12 --(Equal to number of months). Then in dataset data is comng correctly frm the excel file,If I have 13/15/2009 then for this value in dataset "" is there. Y so??.I want the dataset to be filled & want my dates in excel format to be dd/mm/yyyy. I just want that if the date is 13/15/2006,It will come in my dataset ,dat is filled from the excel file.

    Code:
     protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                    //FileUpload1.SaveAs(Server.MapPath("Upload/" + FileUpload1.FileName));
                //String sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Upload/" + FileUpload1.FileName) + ";Extended Properties=Excel 8.0;";
                    String sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileUpload1.PostedFile.FileName  + ";Extended Properties=Excel 8.0;";
                OleDbConnection Exlcon = new OleDbConnection(sConnectionString);
                string sDate="";
                string sRowsNtInserted = "";
                int iRows = 0;
                DateTime date1;
                string sMonthName="";
    
                try
                {
                    Exlcon.Open();
                }
                catch
                {
                    ShowAlertMessage("Please select valid excel file.");
                    return;
                }
                OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", Exlcon);
                OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
                objAdapter1.SelectCommand = objCmdSelect;
                DataSet objDataset1 = new DataSet();
                objAdapter1.Fill(objDataset1, "XLData");

    I have attached the excel file (Pic1).
    In Pic2,I have attached the snapshot of dataset that is filled.
    Attached Images Attached Images   
    Last edited by sonia.sardana; May 14th, 2010 at 01:35 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width