Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I access a Dataset from 2 different foms

Status
Not open for further replies.

dougconran

Technical User
Sep 26, 2003
89
GB
How can I read data in a dataset (created using the Data Adapter Wizard) declared in another form?

I am using the Data Adapter Wizard to set up a connection to an Access database, one table of which I then display in a DataGrid.

This DataGrid serves 2 purposes (1) to provide a means of drilling down to a detail screen when the user clicks on a cell in the first column and (2) to provide a means of multi-selecting a number of rows by clicking on a checkbox in the last column.

Although the datagrid is populated from the dataset I need to manually add the last, checkbox, column as it is not part of the access table. The only way that I have found of making this writeable is to use the Data adapter wizard and then do a dataset.tables(0).columns.add(...). Manually declaring the connection, adapter and dataset seems to force everything to Readonly, even if I explicitely set readonly = false.

Unfortunately, the dataset etc need to be global so that I can read it from the drill down form.

How do I declare an OleDBConnection, OleDBDataAdapter and Dataset to be global when they are created by the Data Adapter Wizard.

TIA

Doug
 
Hi,

I am totally guessing here since have never used the wizards provided in VS.NET. Here goes anyway - I am sure that using the wizards dumps a ton of code in the designer generated code section. Check the access modifiers for the objects that are created, change those to public.

HTH

amit

actually, just fired up a form and added an adapter and a dataset using the wizard, the access modifier is friend i.e. class level. DO you get a compiler error if you try to use the objects?
 
I don't get a compiler error but the objects are not visible from a different form.

I am told that I should declare a dataset along hte following lines:-

Code:
dim ds as application.dataset1 = form1.datasetname

The trouble is that when I type in the 'form1.' a list of selections is displayed which seem to be to do with form1 as a whole rather than the objects in the form.

I guess that what I need to be able to do is to declare the dataset (and other things?) in form1 in such a way that they are visible in other forms using the above syntax - but how do I do that? Especially if I am using the wizard which, for some reason I've yet to fathom, it seems I do?

TIA

Doug
 
Hi,

Could use a public function within form1 like this:
Code:
Public Function GetDataSet()
  return dsForm1
End Function

Which you then call within the other form like this
Code:
dim dsOtherForm as DataSet = form1.GetDataSet()

That way when working with dsOtherForm, you will actually be working with the dsForm1 dataset, so any changes you make, will have effect for dsForm1.

Hope that helps,

Kristof
 
Oops, the function should have a return type ofcourse:

Code:
Public Function GetDataSet() as DataSet
  return dsForm1
End Function
 
Thanks for this - but I'm still getting an error.

This is what I have in Form1 (called nr1_weld_summary)

Code:
    Public Function GetDataSet() As DataSet
        Return ds
    End Function

and this in Form2

Code:
        Dim dr() As DataRow
        Dim ds As DataSet = nr1_weld_summary.GetDataSet()

but when I type in the full stop after nr1_weld_summary the list of options does not include GetDataSet and when I force it in and then compile I get the following error:

Reference to a non-shared member requires an object reference.

If I declare the GetDataSet function as Shared then I get the following error for the line 'Return ds'

Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

and I have absolutely no idea what it means :(

So I'm still no further ahead - just balder!

TIA

Doug
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top