I am trying to work through a sample of exporting a gridview to an excel spreadsheet.
I found the code below on the internet. I pasted it into a test.aspx page.
I need to establish a connection to the NorthWind Database. Can you help me with the code?
Or if you have a better example of exporting a gridview to excel, please share.
Here is the location of the northwind.mdb on my pc: (and is this sample looking for an access database or a sql database...what is the filetype of a sqlserver database?) See code below
c:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\QuickStart\aspnet\samples\data\app_data\northwind.mdb
<%@ Import Namespace="System.IO" %>
<script language="VB" Runat="server">
Sub doExcel(Source as Object, E as EventArgs)
If gv.Rows.Count.ToString + 1 < 65536 Then
Dim tw As New StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Dim frm As HtmlForm = new HtmlForm()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment;filename=" & txtFile.text & ".xls")
Response.Charset = ""
EnableViewState = False
View Complete Post