Net-informations.com
SiteMap  | About    

Insert to Excel file from ASP.NET

The following ASP.NET program insert data into an excel file columns using OLEDB connection . In order to run this program you have to have an existing excel file with two column named as ID and NAME in the specified location of the connection string.

  

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

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

For inserting data into an Excel file using OLEDB , we have to create an insert statement like in SQL operations.

vb.net

  Dim sql As String = "Insert into [Sheet1$] (id,name) values('4','d')"

C#

  string sql = "Insert into [Sheet1$] (id,name) values('3','c')";

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:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
	Width="103px" />
	</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) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.