Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
exporting to excel | Excel Discussion (Misc queries) | |||
Trouble Exporting Word Questionaire into Excel | Excel Worksheet Functions | |||
Exporting from Excel | Excel Discussion (Misc queries) | |||
Exporting to Excel | Excel Discussion (Misc queries) | |||
Trouble exporting chart to htm file - need help | Excel Programming |