Hi is it possible to fill a list box from two SQL tables
firstname lastname
thanks
M
You can always join the 2 tables when quering the db and treat them as 1 afterwards
Thanks for the reply I have tried using
SELECT tenant.firstName, tenant.lastName FROM tenant JOIN Name ON tenant.firstName = firstName.lastName",
I get an error invalid object name Name I thought Name was a temp table?
I should have said fill a list box from two columns in a table
SELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2
Ur not using the join in proper way. Do u have Any relation between the two tables?
Primary key and foreign key constraints?
SELECT tenant.firstName, tenant.lastName FROM tenant JOIN Name ON tenant.firstName = firstName.lastName",
You could create a view by joining both tables and then fill up your listbox from the saved VIEW
I used this to achieve what I wanted
Public Class Tenant
Private _t_id As String
Private _firstName As String
Private _lastName As String
Private _existing As Boolean
Public Property ID() As String
Get
Return _t_id
End Get
Set(ByVal value As String)
_t_id = value
End Set
End Property
Public Property FirstName() As String
Get
Return _firstName
End Get
Set(ByVal value As String)
_firstName = value
End Set
End Property
Public Property LastName() As String
Get
Return _lastName
End Get
Set(ByVal value As String)
_lastName = value
End Set
End Property
Public ReadOnly Property Name() As String
Get
Return LastName & ", " & FirstName
End Get
End Property
Public Property Existing() As Boolean
Get
Return _existing
End Get
Set(ByVal value As Boolean)
_existing = value
End Set
End Property
End Class
Private tenants As New List(Of Tenant)
Private Sub editTennant_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles editTennant.Click
RadPanelEdit.Show()
RadPanelAddTennant.Hide()
Dim connString As String = My.Settings.strConn
Dim conn As New SqlConnection(connString)
Dim reader As IDataReader
Dim cmd As New SqlCommand
cmd.CommandText = "SELECT t_id, firstName, lastName, existing FROM tenant"
cmd.Connection = conn
Try
conn.Open()
reader = cmd.ExecuteReader()
Do While reader.Read()
Dim person As New Tenant()
With person
.ID = reader(0)
.FirstName = reader(1)
.LastName = reader(2)
.Existing = reader(3)
End With
tenants.Add(person)
Loop
Catch ex As Exception
MsgBox(ex.Message)
Finally
conn.Close()
conn.Dispose()
cmd.Dispose()
End Try
End Sub
Private Sub lstAdvocates_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadListControl1.SelectedIndexChanged
If RadListControl1.SelectedIndex > -1 Then
Dim tenants As Tenant = RadListControl1.SelectedItem
RadTextBox5.Text = tenants.ID
RadTextBox6.Text = tenants.FirstName
RadTextBox7.Text = tenants.Existing
RadTextBox8.Text = tenants.LastName
End If
End Sub
Private Sub RadButtonUpdateT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub RadButton1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
Dim tempList As New BindingList(Of Tenant)(tenants)
Dim bsource As New BindingSource
bsource.DataSource = tempList
RadListControl1.DataSource = bsource.DataSource
RadListControl1.DisplayMember = "Name"
RadListControl1.ValueMember = "ID"
End Sub
thanks
M
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.