claire_bicknell
Well-known member
- Joined
- Dec 10, 2008
- Messages
- 49
- Programming Experience
- Beginner
Hi, I am hoping someone might be able to help me.
I have a form which is linked to a SQL Server database.
I have successfully managed to load shop names into a list box and once selected i can generate further information all stored in the same table in the database.
I have one text box left to fill in. This information needs to come from a separate table called dbo.CentreShops. The text box needing to be filled is OpeningClosingTimes.
How can i select from two different tables within a database? I am sure this is fairly simple. Below I have entered the code that it fully functioning but needs altering.
Any help is much appreciated.
I have a form which is linked to a SQL Server database.
I have successfully managed to load shop names into a list box and once selected i can generate further information all stored in the same table in the database.
I have one text box left to fill in. This information needs to come from a separate table called dbo.CentreShops. The text box needing to be filled is OpeningClosingTimes.
How can i select from two different tables within a database? I am sure this is fairly simple. Below I have entered the code that it fully functioning but needs altering.
HTML:
Imports System
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class Stores
'Private places As New Dictionary(Of String, Rectangle)
Const strConnection As String = "Data Source=PC-CLAIRE;Initial Catalog=ShoppingCentre;Integrated Security=True"
Dim con As New SqlConnection(strConnection)
Dim com As New SqlCommand("Select * from dbo.Shops")
Dim myDataAdapter As New SqlDataAdapter()
Dim myDataSet As New DataSet
Public myDataTable As New DataTable
Private Sub Stores_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myDataAdapter.SelectCommand = com
myDataAdapter.SelectCommand.Connection = con
con.Open()
myDataAdapter.Fill(myDataSet, "dbo.Shops")
myDataTable = myDataSet.Tables("dbo.Shops")
'Return myDataTable
con.Close()
Call ListBoxItems()
End Sub
Private Sub ListBoxItems()
con.Open()
Dim maxRowCounter As Integer
Dim intRowCounter As Integer
maxRowCounter = myDataSet.Tables("dbo.Shops").Rows.Count
For intRowCounter = 0 To (maxRowCounter - 1)
ListBox1.Items.Add(myDataTable.Rows(intRowCounter).Item("ShopName"))
Next
con.Close()
End Sub
Private Sub lstProducts_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim con As New SqlConnection(strConnection)
con.Open()
Dim intRow As Integer
intRow = ListBox1.SelectedIndex
'TextBox2.Text = myDataTable.Rows(intRow).Item("OpeningClosingTimes")
TextBox2.Text = myDataTable.Rows(intRow).Item("Description")
TextBox3.Text = myDataTable.Rows(intRow).Item("Website")
' strLoad_File = myDataTable.Rows(intRow).Item("Picture")
' PictureBox1.Load(IO.Path.Combine(Application.StartupPath, strLoad_File))
con.Close()
'com.Connection = con
End Sub
Any help is much appreciated.