Trouble exporting ado rs to Excel

T

Ted

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
 
N

NickHK

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 said:
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
 
T

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
 
N

NickHK

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top