Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
A1VBCode Forums
Home
Search
Members
Calendar
Who's On
Welcome Guest
(
Login
|
Register
)
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
»
Visual Basic (VB 4/5/6)
»
Database Programming
»
filling data in combo box from SQL server
filling data in combo box from SQL server
Rate Topic
Display Mode
Topic Options
Author
Message
buffdaemon_live
buffdaemon_live
Posted 7/22/2008 10:50:48 AM
Forum Newbie
Group: Forum Members
Last Login: 9/4/2008 4:11:31 PM
Posts: 3, Visits: 3
Dear all,
I wanted to fill the combo box with the data from my SQL server database.
There are two column in the table, product_id and product_name.
for example:
product_id| product_name
---------- --------------
1| pencil
2| NoteBook
I was successful in displaying the product name in combo box. The code is given below. I wanted to show the product_name in the combo box and when the user selects the product_name from combo box i should be able to get its product_id. How do i do it? Please help me guys for my academic project.
Below is my code.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New System.Data.SqlClient.SqlConnection("Network Library=DBMSSOCN;" & "Data Source=abacus\mydatabase;" & "Initial Catalog=CADCAM2;" & "Integrated Security =True;" & "MultipleActiveResultSets=True;")
Dim strSQL As String = "SELECT * FROM product"
Dim da As New System.Data.SqlClient.SqlDataAdapter(strSQL, conn)
Dim ds As New DataSet
da.Fill(ds, "product")
With Me.cmbDropDown
.DataSource = ds.Tables("product")
.DisplayMember = "product_name"
.ValueMember = "product_id"
.SelectedIndex = 0
End With
end sub
Private Sub cmbCproduct_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCproduct.SelectedValueChanged
'when the user selects the product_name from the combo box i should be able to get the product_id.
End Sub
Post #25445
Tommy
Tommy
Posted 9/19/2008 10:43:13 PM
Junior Member
Group: Forum Members
Last Login: 10/14/2008 12:47:36 PM
Posts: 17, Visits: 20
Use the SelectedIndexChanged event
Post #25737
« Prev Topic
|
Next Topic »
Reading This Topic
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators:
Brian
,
Peter
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
may
send private messages.
You
cannot
send email's.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Forum Jump...
----------------
Forum Home
Search
Members List
Calendar
Who's Online
----------------
Announcements
|-- Announcements
Visual Basic (VB 4/5/6)
|-- General Visual Basic
|-- Database Programming
|-- COM/ActiveX
|-- API
|-- Internet/Communications Programming
|-- VBA(Excel, Word, etc...)
|-- Game Programming
.NET Programming
|-- Visual Basic .NET/2005/2008
|-- ASP.NET
|-- C#
General Discussion
|-- Forum Feedback
|-- Member Chat
All times are GMT -5:00, Time now is 12:17am