daniness
Well-known member
- Joined
- Feb 12, 2010
- Messages
- 49
- Programming Experience
- Beginner
Hello Everyone,
Could someone please advise on how to go about this? I have a form, frm1 w/a combobox, cboLocations, which is being populated using a sql string. There is also a frm2 w/a series of textboxes and other comboboxes. I want it so that once a selection is made from cboLocations, the textboxes and comboboxes on frm 2 are populated with the corresponding data. Here is what I have so far:
frm1:
frm2:
What's happening right now is that I make a selection from cboLocations on frm1 and click on the OK button, frm2 loads, but none of the textboxes are populating and one of the comboboxes, cboDepot, shows the different data when you click on the down arrow, but it's not displaying anything it its text field when frm2 loads. Any assistance would be greatly appreciated.
Could someone please advise on how to go about this? I have a form, frm1 w/a combobox, cboLocations, which is being populated using a sql string. There is also a frm2 w/a series of textboxes and other comboboxes. I want it so that once a selection is made from cboLocations, the textboxes and comboboxes on frm 2 are populated with the corresponding data. Here is what I have so far:
frm1:
VB.NET:
Public Class frmLocations
Dim conn As New SqlConnection("Data Source=f03d3s-dev01; Initial Catalog=dos_track;User Id=vbuser; Password=tran3;")
Dim depot_refnbr As Integer
Private Sub frmLocation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn.Open()
Call FillCombo()
End Sub
Private Sub FillCombo()
Dim sql As String = "Select distinct Site,depot_refnbr From Locations order by Site asc"
Dim cmd As New SqlCommand(sql, conn)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
Dim dt As New DataTable
da.Fill(ds, "Locations")
Dim dr As SqlDataReader = cmd.ExecuteReader
Do While dr.Read
cboLocations.Items.Add(dr("Site"))
Loop
dr.Close()
cmd.Cancel()
cmd.Dispose()
End Sub
Private Sub cboLocations_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLocations.SelectedIndexChanged
End Sub
Private Sub btnLocationOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLocationOk.Click
clsMain.Location_str_value = cboLocations.Text
'clsMain.Location_depot_refnbr = cboDepot.
Dim f As New frmLocationInfo
f.ShowDialog()
End Sub
End Class
frm2:
VB.NET:
Public Class frmLocationInfo
Dim conn As New SqlConnection("Data Source=f03d3s-dev01; Initial Catalog=dos_track;User Id=vbuser; Password=tran3;")
Private Sub frmLocationInfo_Load(ByVal sender As System.Object, ByVal depot_refnbr As System.EventArgs) Handles MyBase.Load
conn.Open()
Call PopulateTextboxes()
Call FillDepotCombo()
End Sub
Private Sub PopulateTextboxes()
Dim sql As String = "Select distinct site, site_refnbr, aac, telephone_nbr, fax_nbr, email from depot INNER JOIN locations ON depot.depot_refnbr = locations.depot_refnbr"
Dim cmd_txtbox As New SqlCommand(sql, conn)
Dim da_txtbox As SqlDataAdapter = New SqlDataAdapter(cmd_txtbox)
Dim ds_txtbox As New DataSet
Dim dt As New DataTable
da_txtbox.Fill(ds_txtbox, "Locations")
Dim dr_txtbox As SqlDataReader = cmd_txtbox.ExecuteReader
'Read records
Do While dr_txtbox.Read
'txtLoc.Text = "Site"
txtLoc.Text(dr_txtbox("Site"))
Loop
dr_txtbox.Close()
End Sub
Private Sub FillDepotCombo()
Dim sql As String = "Select distinct depot_name, depot_refnbr From Depot order by depot_name asc"
Dim cmdCorrespDepot As New SqlCommand(sql, conn)
Dim daDepot As SqlDataAdapter = New SqlDataAdapter(cmdCorrespDepot)
Dim dsDepot As New DataSet
Dim dtDepot As New DataTable("Depot")
daDepot.Fill(dsDepot, "Depot")
Dim drDepot As SqlDataReader = cmdCorrespDepot.ExecuteReader
'Read records
Do While drDepot.Read
cboDepot.Items.Add(drDepot("depot_name"))
Loop
drDepot.Close()
cmdCorrespDepot.Cancel()
cmdCorrespDepot.Dispose()
End Sub
End Class
Last edited by a moderator: