Export Sql server 2008 Table to Excel using vb2010 RRS feed

  • Question

  •    Private Sub CmdExToExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdExToExcel.Click
            Call Sqlconn.Main()
            Dim objcn As New SqlConnection(cnn)
            Dim objcmd As SqlCommand
            objcmd = New SqlCommand
            Dim aa As String

           objcmd.CommandText = "INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0'," & _
                                "'$Excel 12.0;Database=c:\123.xlsx','SELECT * " & _
                                "FROM [Sheet1$]') SELECT * from attendance"

    End Sub

    i like to export bulk data from sql to excel.  please help me, correct the error



    • Edited by Anbu rose Tuesday, June 30, 2020 4:44 AM
    Tuesday, June 30, 2020 4:41 AM

All replies

  • Hello,

    Although I've not done this operation for many years I do remember that you need to configure SQL-Server as indicated in the following doc page, take time to read it.

    Otherwise at first glance your code looks fine compared to my old code sample.

    Lastly, what exactly is the complete error message?

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Tuesday, June 30, 2020 12:06 PM