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.
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:Actual Payment Date 12/15/2009
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.




Reply With Quote