ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trouble exporting ado rs to Excel (https://www.excelbanter.com/excel-programming/372833-trouble-exporting-ado-rs-excel.html)

Ted

Trouble exporting ado rs to Excel
 
Hi, I am having trouble as a newbee. I am trying to export the dataset to
excel spread sheet. But I am unsure what the recordset object is called in
..net. Here is what I have so far:
Private Sub ExportToExcel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ExportToExcel.Click
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim rng As Microsoft.Office.Interop.Excel.Range
Try
excel = New Microsoft.Office.Interop.Excel.Application
wb = excel.Workbooks.Add()
ws = wb.ActiveSheet()
ws.Range("A1").CopyFromRecordset

excel.Visible = True
wb.Activate()
'Catch ex As COMExceptionMessageBox.Show("Error accessing Excel:
" + ex.ToString())
'Catch ex As ExceptionMessageBox.Show("Error: " + ex.ToString())
Finally

End Try


End Sub

I appoligize but like I said I am new, Can anyone help me out. Thanks, Ted

NickHK

Trouble exporting ado rs to Excel
 
Ted,
The CopyFromRecordset method expects a recordset as an argument to copy
from. Check the Excel Help.
The recordset can be either ADO or DAO.
How you get that in .Net is up to you.

NickHK

"Ted" wrote in message
...
Hi, I am having trouble as a newbee. I am trying to export the dataset to
excel spread sheet. But I am unsure what the recordset object is called

in
.net. Here is what I have so far:
Private Sub ExportToExcel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ExportToExcel.Click
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim rng As Microsoft.Office.Interop.Excel.Range
Try
excel = New Microsoft.Office.Interop.Excel.Application
wb = excel.Workbooks.Add()
ws = wb.ActiveSheet()
ws.Range("A1").CopyFromRecordset

excel.Visible = True
wb.Activate()
'Catch ex As COMExceptionMessageBox.Show("Error accessing

Excel:
" + ex.ToString())
'Catch ex As ExceptionMessageBox.Show("Error: " +

ex.ToString())
Finally

End Try


End Sub

I appoligize but like I said I am new, Can anyone help me out. Thanks,

Ted



Ted

Trouble exporting ado rs to Excel
 
Nick thanks so much for answering but, the question is this. In VB 2005 what
is the recordset called? I mean, I have used the wizards to build my small
application and I did not have to write any ado code it was all written by
vb. So when I call ...copyfromrecordset (rs) It is the (rs) that I do not
know how to call in my appplication. I know this is a stupid question but I
appreciate the help.
Thanks again, Ted

"NickHK" wrote:

Ted,
The CopyFromRecordset method expects a recordset as an argument to copy
from. Check the Excel Help.
The recordset can be either ADO or DAO.
How you get that in .Net is up to you.

NickHK

"Ted" wrote in message
...
Hi, I am having trouble as a newbee. I am trying to export the dataset to
excel spread sheet. But I am unsure what the recordset object is called

in
.net. Here is what I have so far:
Private Sub ExportToExcel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ExportToExcel.Click
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim rng As Microsoft.Office.Interop.Excel.Range
Try
excel = New Microsoft.Office.Interop.Excel.Application
wb = excel.Workbooks.Add()
ws = wb.ActiveSheet()
ws.Range("A1").CopyFromRecordset

excel.Visible = True
wb.Activate()
'Catch ex As COMExceptionMessageBox.Show("Error accessing

Excel:
" + ex.ToString())
'Catch ex As ExceptionMessageBox.Show("Error: " +

ex.ToString())
Finally

End Try


End Sub

I appoligize but like I said I am new, Can anyone help me out. Thanks,

Ted




NickHK[_3_]

Trouble exporting ado rs to Excel
 
Ted,
In VB5/6 and VBA, you would:
Set a Project reference to "MS Active Data objects 2.x".
Then in a suitable location:
Dim Conn As ADODB.Connection
Dim RS as ADODB.RecordSet

Conn...Connect to your DB
Set RS=Conn.Excecute <SQLQuery

Assuming xlWS refers to a valid excel Worksheet
xlWS.Range("A1").CopyFromRecordSet RS

How you achieve that in .Net, I can't tell you.

NickHK

"Ted" ...
Nick thanks so much for answering but, the question is this. In VB 2005
what
is the recordset called? I mean, I have used the wizards to build my
small
application and I did not have to write any ado code it was all written by
vb. So when I call ...copyfromrecordset (rs) It is the (rs) that I do
not
know how to call in my appplication. I know this is a stupid question but
I
appreciate the help.
Thanks again, Ted

"NickHK" wrote:

Ted,
The CopyFromRecordset method expects a recordset as an argument to copy
from. Check the Excel Help.
The recordset can be either ADO or DAO.
How you get that in .Net is up to you.

NickHK

"Ted" wrote in message
...
Hi, I am having trouble as a newbee. I am trying to export the dataset
to
excel spread sheet. But I am unsure what the recordset object is
called

in
.net. Here is what I have so far:
Private Sub ExportToExcel_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles ExportToExcel.Click
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim rng As Microsoft.Office.Interop.Excel.Range
Try
excel = New Microsoft.Office.Interop.Excel.Application
wb = excel.Workbooks.Add()
ws = wb.ActiveSheet()
ws.Range("A1").CopyFromRecordset

excel.Visible = True
wb.Activate()
'Catch ex As COMExceptionMessageBox.Show("Error accessing

Excel:
" + ex.ToString())
'Catch ex As ExceptionMessageBox.Show("Error: " +

ex.ToString())
Finally

End Try


End Sub

I appoligize but like I said I am new, Can anyone help me out. Thanks,

Ted







All times are GMT +1. The time now is 01:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com