This code is being tripped out and I need some help, please

Discussion in 'Visual Studio' started by BillAndrews, Sep 29, 2007.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Protected Function GetData() As System.Data.DataSet


    '--- Function returns a DataSet containing information


    Try


    '--- connection string


    Dim strConn As String = "connection string working"


    '--- create data object


    Dim objConn As New System.Data.OleDb.OleDbConnection(strConn)


    objConn.Open()


    '--- Create objects ready to Grab Data


    Dim objCmd As New System.Data.OleDb.OleDbCommand("Select * From Titles")


    Dim objDA As New System.Data.OleDb.OleDbDataAdapter()


    objDA.SelectCommand = objCmd


    '--- Fill the data set


    Dim objDS As New System.Data.DataSet()


    objDA.Fill(objDS) '--- this is tripping the circuits -- 'System.InvalidOperationException' occurred in System.Data.dll





    '--- clean up and return the Dataset


    objConn.Close()


    Dim strMsg As String


    strMsg = objDS.Tables.Count


    MsgBox(strMsg)


    Return objDS





    Catch


    '--- possible errors include Excel file already open and locked, et al


    Return Nothing


    End Try


    End Function
     
  2. You've opened your connection but you haven't linked the connection to the command, try:

    Dim objCmd As New System.Data.OleDb.OleDbCommand('Select * From Titles', objConn </font>)

    HTH
    Jeff
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page