Net-informations.com
SiteMap  | About    

Read Excel file from ASP.NET

The following ASP.NET application read the content of an Excel file using OLEDB. Here we are using OleDbConnection , OleDbDataAdapter and DataSet for doing this operation in an Excel file. First we have to create an OLEDB connection string to connect the Excel file

  

connStr = "provider=Microsoft.Jet.OLEDB.4.0;Data Source='ExcelFile.xls';Extended Properties=Excel 8.0;";

Data Source='ExcelFile.xls' : we have to specify the Excel file location.

For read the content from an Excel file using ADO.NET , We can use the SELECT command like in SQL Operations.

vb.net

  MyCommand = New OleDbDataAdapter("select * from [Sheet1$]", MyConnection)

C#

  MyCommand = new OleDbDataAdapter("select * from [Sheet1$]", MyConnection);

Default.aspx

  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
	<asp:GridView ID="GridView1" runat="server" />
	</div>
	<asp:Label ID="Label1" runat="server" Text="Message : "></asp:Label>
	&nbsp;
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
default.aspx.cs
default.aspx.vb






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.