How to display more than one value using dataset?

FryDay_Boy

Newcomer
Joined
Jun 10, 2005
Messages
3
Hello all,

I have use the following code to populate a combo box, but I would like to display more than the "empoyee id" (e.g. company, mobile phone number etc etc...) when Button2 is clicked. Can some one please enlighten me ??? Thank you very much !

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connstring As String
Dim cconnection As OleDbConnection
Dim DistrictAdapter As OleDbDataAdapter
Dim ds_name As New Data.DataSet

connstring = ..........
cconnection = New OleDbConnection(connstring)
cconnection.Open()

DistrictAdapter = New OleDbDataAdapter("Select * from [resource master list] where [First Name] = '" & TextBox1.Text & "'", cconnection)
DistrictAdapter.Fill(ds_name, "nametable")

ComboBox1.DataSource = ds_name.Tables("nametable")
ComboBox1.ValueMember = "Employee ID"
ComboBox1.DisplayMember = "LAST NAME"

cconnection.Close()
cconnection = Nothing

End Sub
------------------------------------------------------------------------
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox2.Text = ComboBox1.SelectedValue
End Sub
End Class
 
If you wish to display more than one item in the combobox then try adding a phantom column to rour data set
e.g.
my_dataset.Tables(0).Columns.Add("Full_Name", System.Type.GetType("System.String"), _
"Title_Name + ' ' + First_Name + ' ' + Middle_Name + ' ' + Surname")

This creates a column "Full_Name" that is made up of the other columns. You could then use ComboBox1.DisplayMember = "Full_Name"
 
Back
Top