Click here to Skip to main content
15,885,890 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I have a problem .
I have created a table in SQL called Department
which has followings departmentNames
HumanResource
ComputerScience
MBA

now i want to show these department names in combo box in visual studio 2010
??

Can any one help me ?? plz
Posted

Since you didn't specify the problem more precisely, the steps could be:
 
Share this answer
 
v2
Comments
SaadZulfiqar 11-May-12 14:01pm    
Sir Department is my table name in Database
That table has a coloumn called DeptName which has following contents
HumanResource
ComputerScience
MBA

now i just want to show above contents in Combo Box using visual studio...

i m using connection less approach if u plz help me in showing the contents so can i select the depart ment names from combo box drop down(scroll)
Wendelius 11-May-12 14:03pm    
But if the data is located in the database, then you fetch the data using a connection, right? After you have fetched the data into the datatable the connection isn't needed any more.
SaadZulfiqar 11-May-12 14:05pm    
i will fetch using query and than store it in data set and than what to do ??
Wendelius 11-May-12 14:09pm    
Then you set the datatable as the DataSource of the combobox (the last step in the list)
Maciej Los 11-May-12 14:23pm    
Good answer, my 5!
Use ADO.NET to get the data from database. Once you have the data in datatable, bind the department name & id to the combobox.

Look at these for ADO.NET:
MSDN: ADO.NET[^]
MSDN: Accessing Data with ADO.NET[^]

SQL Query:
SQL
SELECT 
  departmentnames,
  departmentid
FROM
  Department


Properties to use:
MSDN: ComboBox.DataSource Property[^]
MSDN: ListControl.DisplayMember Property [^]
MSDN: ListControl.ValueMember Property[^]
 
Share this answer
 
Comments
Maciej Los 11-May-12 14:23pm    
Good answer, my 5!
Sandeep Mewara 12-May-12 3:57am    
Thanks losmac.
Wendelius 11-May-12 17:01pm    
Good collection of links!
Sandeep Mewara 12-May-12 3:57am    
Thanks Mika.
Monjurul Habib 11-May-12 18:04pm    
5!
Hi,
Your easy and best solution here:
sp_helptext[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900