Click here to Skip to main content
15,891,849 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I am trying to export from sql query to excel as shown below

VB
Dim mstrExcelQuery As String
            Dim commExcel As New SqlCommand
            conn = New SqlConnection("Data Source=MIL-Dev2-PC;Initial Catalog=meridian;User Id=sa;Password=master")
            conn.Open()
            mstrExcelQuery = "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
                     "].[" & strWorksheet & "] FROM " & "[" & FinalQuery & "]"
            commExcel = New SqlCommand(mstrExcelQuery, conn)
            commExcel.ExecuteNonQuery()
            commExcel.Dispose()
            conn.Close()
            SaveFileDialog1.Dispose()
            MsgBox("Report Saved to Excel!!", MsgBoxStyle.Information)


My strExcelfile=C:\Users\MIL-DEV2\Desktop\ExportExcel.xls

strWorkSheet=Rpt

mstrExcelQuery = Select * from TransactionMaster where CustomerName='Deepak'


But here I am getting an error "Invalid object name 'Select * from TransactionMaster where CustomerName='Deepak''"


ANy help is kindly appreciated
Posted

 
Share this answer
 
Check this it will help you

Export to Excel using VB.Net[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900