View Single Post
  #1 (permalink)  
Old July 1st, 2009, 12:34 PM
bex bex is offline
Friend of Wrox
Points: 643, Level: 9
Points: 643, Level: 9 Points: 643, Level: 9 Points: 643, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2008
Location: london, , United Kingdom.
Posts: 153
Thanks: 7
Thanked 1 Time in 1 Post
Default How to bind a ListBox to datadase

I need a way to display 3 columns data in ListBox

I Have this code:

Code:
 
Dim cnn As SqlConnection = New SqlConnection("Data Source=SQL1;Initial Catalog=Tracking;Integrated Security=True")
' Connect to the database
' Create a new ad hoc query to retrieve customer names
Dim cmd As SqlCommand = cnn.CreateCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT CNAM05 , CUSN05 , PCD105  FROM table1 Where (CNAM05 Like '" & TextBox1.Text & "%')"
' Dump the data to the user interface
cnn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
DoWhile dr.Read()
ListBox1.Items.Add(dr.GetString(0))
Loop
' Clean up
dr.Close()
cnn.Close()
this returns data from 1 column, I need to display Name -- Address--Post Code. but when i select an item only the value of name should be past



thanks in advance
__________________
bx

Last edited by bex : July 1st, 2009 at 04:39 PM.
Reply With Quote