Getting tripped out here  -- need some help

Posted on 2007-09-29
Last Modified: 2013-11-26
  Protected Function GetData() As System.Data.DataSet
        '--- Function returns a DataSet containing information
            '--- connection string
            Dim strConn As String = "Provider"  '--- connection works

            '--- create data object
            Dim objConn As New System.Data.OleDb.OleDbConnection(strConn)

            '--- 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

            '--- clean up and return the Dataset

            Dim strMsg As String

            strMsg = objDS.Tables.Count


            Return objDS

            '--- possible errors include Excel file already open and locked, et al
            Return Nothing
        End Try

    End Function
Question by:Hiddenattractor
    LVL 16

    Accepted Solution

    You aren't telling the command object (and thus the data adapter) which connection to use. Change your command object's initialization to this:
    Dim objCmd As New System.Data.OleDb.OleDbCommand("Select * From Titles", objConn)


    Author Comment

    That Worked great but how can I now change the strMsg = objDS.Tables.count to
    something like
    strMsg = objDS.Fields("title").value '--- I used to use this with ADO 2.0
    LVL 16

    Expert Comment

    what do you want strMsg to be? If you want it to be the value of a column from one of the rows of your data table you'd do something like this to get the first row's column "title" value:

    strMsg = objDS.Tables(0).Rows(0).Item("title").ToString()

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now