top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can we export a table from sql server 2008 to ms excel but by vb.net coding

+2 votes
531 views
Can we export a table from sql server 2008 to ms excel but by vb.net coding
posted Apr 12, 2014 by Neeraj Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Suppose you want to export the whole data in one table from sql server 2008 directly using vb.net to EXCEL? You can use the following code -

Dim dt As DataTable = GetData()
Dim attachment As String = "attachment; filename=Employee.xls"
Response.ClearContent()
Response.AddHeader("content-disposition", attachment)
Response.ContentType = "application/vnd.ms-excel"
Dim tab As String = ""
For Each dc As DataColumn In dt.Columns
    Response.Write(tab + dc.ColumnName)
    tab = vbTab
Next
Response.Write(vbLf)

Dim i As Integer
For Each dr As DataRow In dt.Rows
    tab = ""
    For i = 0 To dt.Columns.Count - 1
        Response.Write(tab & dr(i).ToString())
        tab = vbTab
    Next
    Response.Write(vbLf)
Next
Response.End()

Source: http://stackoverflow.com/questions/5621577/export-from-sql-server-to-excel-file-using-asp-net-and-vb-net

answer Apr 17, 2014 by Chahat Sharma
Similar Questions
+4 votes

How can I save image in SQL SERVER by VB.NET?

+10 votes

I have 15-20 tables and i want to export the data from those tables to excel.

...