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

COMMENT USING
PREMIUM SPONSORS
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.
More Blogs from this Blogger
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.