matt09524 Posted October 8, 2005 Posted October 8, 2005 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 won't 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 won't 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 can't use the wizard anymore. Quote
bri189a Posted October 8, 2005 Posted October 8, 2005 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. ... Take it outside of try ...anywhere else it's out of scope. Quote
Administrators PlausiblyDamp Posted October 8, 2005 Administrators Posted October 8, 2005 You will need to declare MyDS outside of the form load if you want it to be used in other methods of the form. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
bri189a Posted October 8, 2005 Posted October 8, 2005 Sorry thought you were just trying to get it in other places in the method, not the form...my fault for not reading thoroughly. ;) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.