I have this working on VB6 that saves a query in a excel sheet:
Code:
Dim xlApp As Object
Dim cn as new ADODB.connection
Dim sql as String
'Connect to database
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & App.Path & "\temp.mdb;"
'Create excel object
Set xlApp = CreateObject("Excel.Application")
xlApp.Application.Workbooks.Open (App.Path & "\" & XLSNombre & ".xls")
xlApp.Application.Visible = True
'Close object (it doesnt allow insert of values with object open)
xlApp.Application.ActiveWorkbook.Close savechanges:=True
xlApp.Quit
'Insert values
sql = "SELECT * INTO [Excel 8.0;Database=" & App.Path & _
"\" & XLSNombre & ".xls].[Inicial] FROM Table where seccion='Inicial' or seccion='Suplente Inicial' order by seccion,nombre;"
cn.Execute sql
The XLSNombre is a variable with the name of the excel file that has been set before.
The connection I have in .NET is to SQL server (but is the same).
How can I use this code (or..how can I make this code work for .NET) or what is the equivalent of this for .NET?
I found some solutions but with inserts of single rows or I have to set the title of the columns, I dont find any "simple" solution to do an "insert into" (like the code I use in VB6).
Thanks!