How Do I Create 2 linked Dataform wizard forms?


Well-known member
Oct 21, 2004
Programming Experience
My Visual Studio .NET project involves using the dataform wizard to create a form DataForm1 displaying an SQL2000 database table in a dbgrid. (no Problem)
Then I add a second dataform wizard form DataForm2 to display the same database table in the single record textbox format. (no problem)
I want to add a button on DataForm1 to access DataForm2 and have DataForm2 load the current record from the datagrid on DataForm1. Really simple - I thought.

Dim frmDF2 AsNew DataForm2

What I need:
Do I need to recode DataForm2 btnLoad_Click procedure to display the record in focus on DataForm1 and then copy it to the DataForm2_Load procedure?

Do I need to call DataForm2 in a different manner?

Both forms were created with an instance of objdsPart on them - this is the dataset I want to use. The only OleDbDataAdapter and OleDbConnection reside on DataForm1. Is This Correct?

Eventually I would like to add a doubleclick method to the dbgrid to display DataForm2 also.

Delphi3 did this automatically by keeping the dataset open and in focus throughout the project. Visual Studio .net does not behave this way. The dataset is actually a table in memory? Can I reference the record position from another form? Do I reference the OleDBDataAdapter1 or the objdsPart dataset? I will need this knowledge for just about every table that I access. Any tutoring would be greatly appriciated.
Last edited:
How is DataForm2 getting the data from the database if it doesn't have a DataAdapter or Connection? Are you passing the data from DataForm1 to DataForm2 or sharing the Adapter and connection?

The dataSet is actually a table in memory. If you use the standard DataForm Wizard to create both forms, I would guess that both forms would have a DataSet, DataAdapter and DataConnection. Anyway, you say both have an instance of the dataSet objdsPart. If you are using DataForm2 to edit the record as it seems, a good design would involve only one dataset (with two dataSets, you are accessing the data twice from the dataBase or at least doubling the memory for data storage).

As always there are many solutions to this. One would be to declare the dataSet in a module so that both forms could access it. In DataForm1 you would load the data.

To send the record position to DataForm2, create a public variable in DataForm2 and set that variable when instantiating DataForm2:
'in DataForm2 (outside of any procedures, i.e. a class member):
Public iRecord as Integer
'in the button's click event handler 
'or DataGrid's doubleClick event handler on DataForm1:
Dim frmDF2 As New DataForm2
frmDF2.iRecord = RecordNumber
Then in DataForm2's load event handler, set the dataBinding position based on iRecord.

You could also create a seperate class that contains the dataSet and all the functions to interface with the dataBase, often called a business class.
I would like to set up the Part DataSet as a business class. What are the steps to do this and how is the class accessed from the different forms.

I can pass the current record to the edit form (DataForm2) but the updates are not passed back to the display form (DataForm1). When is the actual database to be updated and how are the updates refreshed on the grid. A seperate module to handle all Part dataset access and update would take care of this?

again, sorry for the simplicity of this application. I'm just getting my feet wet with VB.

I want a Part dataset displayed on a component1.trueDataGrid on DataForm1, I want to sort/filter for a specific part number and press a button to access a seperate form (dataForm2). DataForm2 will display only the selected record and allow the user to edit the record. When the record is updated I want to close DataForm2 and have the Changes reflected in DataForm1's DataGrid. Each and every Dataset I use for the rest of the project will have this functionality for record updates, I need to understand the underlying process and create a master template that I can copy and change for each database.
I have shelves of books to reference, but they all stop shortly after remedial programming of way too simple applications.

Can You steer me in the right direction?

thanks for the assistance.

Latest posts