MDI SQL connection problem

dswigart

New member
Joined
Jun 5, 2003
Messages
4
I have a problem figuring out how to get from VB6 to VB.Net when it comes to Parent / Child Forms.

From what I can tell, I have to create the form and then create an instance of it.

This is what I have done:
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
Dim Employees As New frmEmployees()
Employees.MdiParent = Me
Employees.Show()
End Sub

The form has 3 sql connections and several DataSets. The default connection strings are set for each sql data adapter.

When the child form loads the following sub is run:
Private Sub frmEmployees_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Loaded = False
Call LoadTables()
ComboBox1.SelectedIndex = 1
RadioButton1.Checked = True
Loaded = True
End Sub frmEmployees_Load

The first few lines of PRIVATE SUB LoadTables are:

Private Sub LoadTables()
DsEmployees1.Clear()
DsCopy21.Clear()
DsCopy31.Clear()
DsAllDeductions1.Clear()
DsAllEarnings1.Clear()
DsRegRep1.Clear()
DsRegRep21.Clear()
sdaFedMStatus.Fill(DsCopy21)

When I exit the Child form the following code is executed:

Private Sub frmEmployees_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Try
SqlConnection1.Close()
Catch
End Try
SqlConnection1.Dispose()
MsgBox(ChangedMain)

End Sub frmEmployees_Closing

HERES MY PROBLEM.

When I close the Child form and try to reaccess it from the Parent I get an error on the line "sdaFedMStatus.fill(DsCopy21). The error says:

The SelectCommand property has not been initiallized before calling "Fill

WHY DOES THIS ERROR HAPPEN ON THE SECOND CALL OF THE FORM AND NOT ON THE FIRST?

HOW DO I CORRECT THIS PROBLEM.:confused:
 
Where are you assigning the SQL to the adapter? cause I belive that is what is not being called.

Why not use the Step Through on the Debugger

Andy
 
The sql is in the properties for the data adapter.

The first time that the form is called there is no problem.

It only gives a problem on the second load. As if it were trying to make a duplicate connection.

The step through just stops me on the first "fill" statement.
 
Right this should work when opening the form your code will look somthing like...

Code:
Formname.mdiparent = me
Formname.Show

change it to somthing like the following

Code:
formname.dispose
formname = New formclass()
formname.mdiparent = me
formname.show

Form name is whatever you called the form e.g Form1
Formclass is the name of the class of that form

That shoud work as it disposes of the old form and created a new one as in the first time the form works

Andy
 
I changed the code in the MDI form to:
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
Dim employees As New frmEmployees()
employees.Dispose()
Employees = New frmEmployees()
Employees.MdiParent = Me
Employees.Show()
End Sub

now it doesnt work the first time I enter the form.

In several ways Ive seen so far.... VB6 was much easier to use than VB.NET
 
My methord will not work as I thought you were creating a single instance of the form so remove my bit as they will make no diffrence any way.

Can you attach the source so I can have a better look

and in regards to VB6 being better than VB.NET it takes time getting used to because everything is so much more structured now. I said exactly the same 6 months ago now I carnt even look at VB6

Andy
 
Back
Top