Ok so I needed to dump all the data my program pulled in to a new Excel Workbook. I found this awesome example, until I remembered I'm no longer using an ADODB record set, but an ADO.NET DataTable. Microsoft of course says that CopyFromRecordset doesn't work (make sense), but to look deeper in for an example how to do this with ADO.NET instead. Lo and behold instead of an example that tells me how to do this it gives me only an example of how to add data to an EXISTING workbook. If I don't believe in Microsoft will they die? No one clap now.
Here is the ADODB Code changed to what I needed if I was still using ADODB. Any ideas how to change this to what I need for ADO.NET?
-I hate Microsoft!
-Forever and always forward.
Here is the ADODB Code changed to what I needed if I was still using ADODB. Any ideas how to change this to what I need for ADO.NET?
Code:
Public Delegate Sub tDataToExcel(ByVal rSet As ADODB.Recordset, ByVal WorkbookLocation As String, ByVal WorkbookName As String)
Public Sub DataToExcel(ByVal rSet As ADODB.Recordset, ByVal WorkbookLocation As String, ByVal WorkbookName As String)
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)
Dim n As Int32
For n = 1 To rSet.Fields.Count
oSheet.cells(1, n).value = rSet.Fields(n - 1).Name
Next
oSheet.Range("A2").CopyFromRecordset(rSet)
oBook.SaveAs(WorkbookLocation & WorkbookName)
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
End Sub
-I hate Microsoft!
-Forever and always forward.