ado.net and combo box

Cmr

Member
Joined
May 16, 2006
Messages
17
Programming Experience
1-3
I have used ADO.NET and SQL SERVER in my small application.
Details as below


VB.NET:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Dim MyCon As SqlConnection
Dim MySelect As SqlCommand
Dim MyDr As SqlDataReader
 
MyCon = New SqlConnection("server=ddd;Database=BankDetails;Trusted_Connection=True;")
MyCon.Open()
 
MySelect = New SqlCommand("select distinct(pid) from CustomerDetails", MyCon)

Now to my question
1.)I have a combo box where I want to have the list of PID
How to connect it to data source.
2.) Is combo box ok. or I am supposed to go for DBCombobox

Kindly let me know
Thank You
Hemalatha
 
Last edited by a moderator:
You may ahve to do some more typing yet...

Run the query, pulling the resu;ts into a datatable. Set that datatable to be the DataSource of the combo. I do this with normal combos - i never heard of a DBCombo
 
I got the answer

Its this way
I populate the combo box first by the following code
MyCon.Open()
MySelect = New SqlCommand("select pid from CustomerDetails", MyCon)
MyDr = MySelect.ExecuteReader
cboDSEARCH.Items.Clear()
While MyDr.Read
cboDSEARCH.Items.Add(MyDr("pid"))
End While
MyCon.Close()
 
You'd make a dataadapter with that sql and use it to fill a datatable
Then you assign the datatable to the datasource of the combo box
Then you set the displaymember and valuemember properties appropriately

For more info on data access in general, click the DW1 link in my signature
 
Back
Top