Excel Data Reading issue in C#

377 views Asked by At

I am doing to create a page in which I can read data from excel sheet and upload in database, If all columns have value then there is no issue, while facing issue when some column not have values!

This is my code

if ((this.drp_Sheet.SelectedValue == "Well Test") && this.fileuploader.HasFile)
                {
                    try
                    {
                        string fileName = Path.GetFileName(fileuploader.FileName);
                        string extension = Path.GetExtension(fileName);
                        fileuploader.SaveAs(base.Server.MapPath("~/Files/") + fileName);
                        string FilePath2 = base.Server.MapPath("~/Files/") + fileName;
                        DataTable table5 = new DataTable();
                        DataSet set5 = new DataSet();
                        if (extension.Contains(".xlsx") || extension.Contains(".xls") || extension.Contains(".xlsm"))
                        {
                            
                            IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fileuploader.FileContent); 
                            
                            set5 = excelReader.AsDataSet();
                            table5 = set5.Tables[0];
                            grv_WellTest.DataSource = table5;
                            grv_WellTest.DataBind();
                            Session["DT_WELLTEST"] = table5;
                        }
                    }
                    catch (Exception exception6)
                    {
                        this.Info.Text = exception6.Message;
                    }
                    finally
                    {
                        dt_Out.Rows.Clear();
                        dt_tmp.Rows.Clear();
                    }

My excel data sheet is look like this enter image description here

While reading excel file I populatas data set values in a gridview at user end for checking, but missing some column values which is written on red color as enter image description here

Why the values are missing I can't find any clue. I change excel sheet, written values on new excel sheet and try to read values but same issue occur. Please help me out this unresolved issue please

0

There are 0 answers