Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

Getting tripped out here -- need some help

  Protected Function GetData() As System.Data.DataSet
        '--- Function returns a DataSet containing information
        Try
            '--- connection string
            Dim strConn As String = "Provider"  '--- connection works

            '--- 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
0
Hiddenattractor
Asked:
Hiddenattractor
  • 2
1 Solution
 
TSmoothCommented:
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)



0
 
HiddenattractorAuthor Commented:
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
0
 
TSmoothCommented:
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()
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now