Using ADODB.Recordset in VB.NET 2008

Discussion in 'Visual Basic ( VB )' started by bsms, Jul 29, 2009.

  1. bsms

    bsms New Member

    Joined:
    Jul 29, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I am working in VB.NET 2008, trying to run a query on the database MyDatabase#1.sdf and output the results to an Excel spreadsheet via an ADO Recordset.

    Code:
    Imports Excel = Microsoft.Office.Interop.Excel
    Imports System.Data
    Imports System.Data.OleDb
    Imports ADODB
    Imports System.Data.SqlClient
    Imports System.Console
    Imports System.Data.SqlServerCe
    Imports Microsoft.VisualBasic
    
    Public Class Form3
    
        Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim rs As New ADODB.Recordset
            Dim dbConnection As SqlCeConnection
            dbConnection = New SqlCeConnection("Persist Security Info = False; Data Source = C:\Documents and Settings\Desktop\MyDatabase#1.sdf")
    
            ' Create the connection string.
            dbConnection.Open()
    
            'Create the SQL statement.
            Dim testCommand As SqlCeCommand = New SqlCeCommand("SELECT * FROM Name")
           
            'Create the recordset and run the query.
            rs = New ADODB.Recordset
            rs.Open(testCommand, dbConnection, 0, 1, 1)
    ....
    
    I keep getting errors with this line:
    rs.Open(testCommand, dbConnection, 0, 1, 1)

    The error reads: COMException was unhandled. Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

    Any ideas on what the problem might be?? I am fairly new at all of this and really confused.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    What happens if you use just "SELECT * FROM Name" instead of testCommand?
     
  3. bsms

    bsms New Member

    Joined:
    Jul 29, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Unfortunately it still does not work. I am still having the same problem.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice