Some record in Excel sheet not displaying due when exporting data using OLEDB in ASP.Net

Last Reply on Nov 18, 2013 10:14 PM By Mudassar

Posted on Nov 18, 2013 06:33 AM

 

            string conStr = "";

            switch (Extension)
            {

                case ".xls": //Excel 97-03

                    conStr = ConfigurationManager.ConnectionStrings["Excel03ConString"]

                             .ConnectionString;

                    break;

                case ".xlsx": //Excel 07

                    conStr = ConfigurationManager.ConnectionStrings["Excel07ConString"]

                              .ConnectionString;

                    break;

            }

            conStr = String.Format(conStr, FilePath);

            OleDbConnection connExcel = new OleDbConnection(conStr);

            OleDbCommand cmdExcel = new OleDbCommand();

            OleDbDataAdapter oda = new OleDbDataAdapter();

            DataTable dt = new DataTable();

            cmdExcel.Connection = connExcel;



            //Get the name of First Sheet

            connExcel.Open();

            DataTable dtExcelSchema;

            dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

            string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();

            connExcel.Close();



            //Read Data from First Sheet

            connExcel.Open();




            ///
            cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";

            oda.SelectCommand = cmdExcel;

            oda.Fill(dt);


            connExcel.Close();
            int count = dt.Rows.Count;
          string[] address = new string[count + 2];
            for (int i = 0; i < count; i++)
            {
                address[i] = "";
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    address[i] = address[i] + dt.Rows[i][j].ToString() + ",";
                }
                //Label1.Text = address[i].ToString();
            }

mt data table not matches with current excel help me

 

Posted on Nov 18, 2013 10:14 PM

Your code is correct, you will need to check the format of the dates that are missing, it might be possible due to bad data it is not displaying