Name 'MyDS' not declared. ???

matt09524

Well-known member
Joined
Sep 14, 2005
Messages
47
Code:
Try
            Dim con As New OleDbConnection connection. 
            Dim da As New OleDbDataAdapter data adapter for connection. 
            Dim MyDS As New DataSet  dataset to be filled by data adapter. 

            Dim querySQL As String = "SELECT * FROM dbinfo ORDER BY dblast"
            Dim connectString As String = "Provider= Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\dbdata.mdb"

            con = New OleDbConnection(connectString)
            da = New OleDbDataAdapter(querySQL, connectString)
            da.Fill(MyDS)

        Catch ex As Exception
            Dim form7 As New Form7
            form7.Show()
            DBError()  Disables all but the restore button.
        End Try

The above code works fine. However, if I try to use the MyDS dataset name anywhere, in any other section of the app, I get the "Name MyDS not declared." This is driving me nuts.

That code is in the form_load procedure. If I try to call myds anywhere inside or outside the load procedure, it wont work. the da.fill(myds) works fine (does not give me an error during design) and I can compile it. But if I try to add something like

records = me.bindingcontext(myds, "dbinfo").count

it wont take that. When I had the dataset configured by the designer wizard, this all worked fine, but my requirements have changed since then and I cant use the wizard anymore.
 
matt09524 said:
Code:
Try
            Dim con As New OleDbConnection connection. 
            Dim da As New OleDbDataAdapter data adapter for connection. 
            Dim MyDS As New DataSet  dataset to be filled by data adapter. 
...
[/QUOTE]

Take it outside of try ...anywhere else its out of scope.
 
Sorry thought you were just trying to get it in other places in the method, not the form...my fault for not reading thoroughly. ;)
 
Back
Top