Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/10/2014, 09:27
CrepuX
 
Fecha de Ingreso: mayo-2007
Mensajes: 35
Antigüedad: 17 años
Puntos: 0
Rellenar Excel con Consulta SQL Server

Hola a todos/as

Estoy intentando llenar un Excel mediante una consulta en SQL, pero me da un error "Error de Sintaxis en la cláusula FROM"

Mi código es el siguiente:

Dim cadena As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Computer.FileSystem.SpecialDirectories.Desktop & "\Informe.xls;Extended Properties='Excel 8.0;HDR=YES;'"

Using cnn As New OleDbConnection(cadena)

sql = "SELECT [Campo1], [Campo2], [Campo3], [Campo4] INTO[Hoja] FROM [Base].[dbo].[NombreVista]
"IN ''[ODBC;Driver={SQL Server};
Server=servidor;
Database=base;
Trusted_Connection=yes]"

Dim cmd As New OleDbCommand(sql, cnn)

Try
cnn.Open()
Dim n As Integer = cmd.ExecuteNonQuery

Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Using

Alguna idea de qué estoy haciendo mal??

Desde ya, muchas gracias.