RE:Exportar Dataset a Excel
Hola:
He visto el ejemplo que pones y no lo llego a entender del todo.¿Te es mucha molestia explicarmelo?
Te pongo lo que no entiendo con "***"
'Create a Recordset from all the records in the Orders table.
Dim sNWind As String
******** Sii quiero usar un dataset ?? ******
******** Dim conexión As New OleDbConnection(cadenaDeConexión)
******** Dim comm As New OleDbCommand
******** comm.CommandText = "SELECT * FROM Clientes"
******** comm.Connection = conexión
******** Dim ds As New DataSet
******** Dim da As New OleDbDataAdapter(comm)
******** conexión.Open()
******** ******** ******** ******** ******** ******** ********
Dim conn As New ADODB.Connection()
Dim rs As ADODB.Recordset
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
sNorthwind & ";")
conn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rs = conn.Execute("Orders", , ADODB.CommandTypeEnum.adCmdTable)
****** No sé como modificarlo **************
'Create a new workbook in Excel.
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)
'Transfer the field names to Row 1 of the worksheet:
'Note: CopyFromRecordset copies only the data and not the field
' names, so you can transfer the fieldnames by traversing the
' fields collection.
Dim n As Int32
For n = 1 To rs.Fields.Count
oSheet.Cells(1, n).Value = rs.Fields(n - 1).Name
Next
'Transfer the data to Excel.
oSheet.Range("A2").CopyFromRecordset(rs)
******* ¿Cómo hago para pasarlo a Word? ********
'Save the workbook and quit Excel.
oBook.SaveAs(sSampleFolder & "Book3.xls")
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
'Close the connection
rs.Close()
conn.Close()
SALUDOS y GRACIAS