Blog

How to Read Excel File using ASP.NET

Posted by Hussain Munaf Blogs | ASP.NET Programming Nov 29, 2012
Today I am Sharing Excel Reader to read Excel file from Asp.net C#.
Download Files: excelread.zip

Today I am Sharing Excel Reader to read Excel file from Asp.net C#.

This is database in Excel:

Image1.jpg

This is Codes:

using System;
using
System.Data;
using
System.Data.OleDb;

public
partial class ExcelReader : System.Web.UI.Page
{
    OleDbConnection olcon = new OleDbConnection(
@"Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data
Source=E:\exceldatareader\excelread\info.xlsx

;Mode=Share Deny Write;Extended Properties=""HDR=YES;"";Jet OLEDB:Engine Type=37"
);
    OleDbDataAdapter olda;

    protected void Page_Load(object sender, EventArgs e)
    {
       
try
        {
            olcon.Open();
            string query = "select [ID],[Name],[Business] from [Sheet1$]";
            olda = new OleDbDataAdapter(query, olcon);
            DataSet ds = new DataSet();
            olda.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        catch (Exception ex)
        {
           Response.Write(ex.Message + ex.StackTrace); }
       
finally
        { olcon.Close(); }
    }
}

This is Result:

Image2.jpg

post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
More Blogs from this Blogger
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts