thanks for your replies,
After many trials and errors, I have fixed the connection problem taking all your suggestions into consideration. What i did is i opened a new module to open the connection and calls it whenever i need it.
Now i have a bigger problem as i advanced with my combo. im not pasting the entire code, since it will be too messy :P
I have 3 combo and 3 different table in my database. all this are related ... i want the first combo to display the Product i publish the combo on form load
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cmd2 As OleDbCommand = New OleDbCommand("SELECT ProductID, ProductName FROM Products", con)
' some code follows
' and after all the dataset
da2.Fill(ds2, "Product")
With cmbProduct
.DataSource = ds2.Tables("product")
.DisplayMember = "ProductName"
.ValueMember = "ProductID"
.SelectedIndex = 0
End With
End Sub
Now this Product have a sub product i want to filter the next combo by productID i.e i select the product i want the corresponding sub-product to be shown in the combo2
Private Sub cmbProduct_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbProduct.SelectedIndexChanged
qry = "SELECT * FROM subp WHERE ProductID = " & cmbProduct.SelectedValue.GetHashCode & " order by subitem"
da.Fill(ds, "product")
With cmbSubP
.DataSource = ds.Tables("product")
.DisplayMember = "SubItem"
.ValueMember = "ProductID"
'.SelectedIndex = -1
End With
end sub
Everything works normal till here.
My headach starts from the next code where i have to filter combo3 using the items from combo2
Private Sub cmbSubP_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSubP.SelectedIndexChanged
qry1 = "SELECT * FROM subtype WHERE psubID = " & cmbSubP.SelectedValue.GetHashCode & " "
da1.Fill(ds1, "subtype")
With cmbType
.DataSource = ds1.Tables("subtype")
.DisplayMember = "type"
.ValueMember = "psubID"
'.SelectedIndex = 0
End With
end sub
The codes always return the value of the first combobox, i'm totally lost, the last combo cmbType wouldn't update corresponding to the second combo(cmpSubP), instead it always return the value of combo1 (cmbProduct)
Please tell me if theres a better approach to this, i've been tryin and browsing the net for two straigh nights now :P can't get it to work