Register and join over 40,000 other developers!
Recent Topics
-
Tekken 7
IsrealJones - Mar 22 2021 07:21 AM
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
New to the community
iwinx - Jul 17 2020 12:02 PM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

4 replies to this topic
#1
Posted 09 September 2012 - 03:12 AM
Need help:
Sub combofill()
Dim dat As SqlDataAdapter = New SqlDataAdapter("select lname + ' ' + fname + ' ' + mname as store_forcom from tblaccount", con)
dat.Fill(dats, "tblaccount")
Me.ComboBox1.Items.Clear()
Me.ComboBox1.DisplayMember = "store_forcom"
Me.ComboBox1.ValueMember = "account_id"
Me.ComboBox1.DataSource = dats.Tables("tblaccount").DefaultView
End Sub
I binded the columns lname,fname,mname to the combobox and what I want is to get the ID everytime the combobox's index changes.
Heres the code for the combobox index change:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Label1.Text = ComboBox1.SelectedValue.ToString()
End Sub
It gives 'System.Data.DataRowView'. It works if only one column.
Sub combofill()
Dim dat As SqlDataAdapter = New SqlDataAdapter("select lname + ' ' + fname + ' ' + mname as store_forcom from tblaccount", con)
dat.Fill(dats, "tblaccount")
Me.ComboBox1.Items.Clear()
Me.ComboBox1.DisplayMember = "store_forcom"
Me.ComboBox1.ValueMember = "account_id"
Me.ComboBox1.DataSource = dats.Tables("tblaccount").DefaultView
End Sub
I binded the columns lname,fname,mname to the combobox and what I want is to get the ID everytime the combobox's index changes.
Heres the code for the combobox index change:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Label1.Text = ComboBox1.SelectedValue.ToString()
End Sub
It gives 'System.Data.DataRowView'. It works if only one column.
#2
Posted 09 September 2012 - 03:50 PM
You set the CombBox's ValueMember to 'account_id'. Does the default DataView from DataTable tblaccount has the account_id property in it?
Also, please check for 'Nothing' of the SelectedValue property/column in ComboBox SelectedIndexChanged event as follows.
Also, please check for 'Nothing' of the SelectedValue property/column in ComboBox SelectedIndexChanged event as follows.
System.EventArgs) Handles ComboBox1.SelectedIndexChanged If (ComboBox1.SelectedValue <> Nothing) Label1.Text = ComboBox1.SelectedValue.ToString() End Sub
#3
Posted 10 September 2012 - 05:13 AM
1) Run your query in SSMS to verify what is coming back from the query.
2) Put a breakpoint on the ComboFill routine and step through it, once again verifying what is coming back from the DB, etc.
Your code doesn't show a declaration for the variable: dats
I'm also assuming that con is open?
Why aren't you declaring a DataTable variable and filling that?
Dim dt as DataTable = New DataTable()
Dim dat As SqlDataAdapter = New SqlDataAdapter("select lname + ' ' + fname + ' ' + mname as store_forcom from tblaccount", con)
dat.Fill(dt, "tblaccount")
Me.ComboBox1.Items.Clear()
Me.ComboBox1.DataSource = dt
Me.ComboBox1.DisplayMember = "store_forcom"
Me.ComboBox1.ValueMember = "account_id" <== This field is not in your query
2) Put a breakpoint on the ComboFill routine and step through it, once again verifying what is coming back from the DB, etc.
Your code doesn't show a declaration for the variable: dats
I'm also assuming that con is open?
Why aren't you declaring a DataTable variable and filling that?
Dim dt as DataTable = New DataTable()
Dim dat As SqlDataAdapter = New SqlDataAdapter("select lname + ' ' + fname + ' ' + mname as store_forcom from tblaccount", con)
dat.Fill(dt, "tblaccount")
Me.ComboBox1.Items.Clear()
Me.ComboBox1.DataSource = dt
Me.ComboBox1.DisplayMember = "store_forcom"
Me.ComboBox1.ValueMember = "account_id" <== This field is not in your query
My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth
#4
Posted 13 September 2012 - 10:23 AM
how to put a breakpoint?
#5
Posted 13 September 2012 - 10:28 AM
you can either click in the lefthand side of the line and a breakpoint (red symbol) will toggle on/off. You can also right click on a line and select insert breakpoint. But your problem is that account_id is not in your sql query. Add it, check my answer above, and it should work.
My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth
Also tagged with one or more of these keywords: Id, multiple columns, combobox
![]() How to receive random id from DataBase?Started by AdrianWiercioch, 10 Dec 2014 ![]() |
|
![]() |
||
Language Forums →
HTML, CSS and Javascript →
how to deal with the forms indtified with idStarted by scseguanshui06, 20 Jul 2014 ![]() |
|
![]() |
||
Tutorial Forums →
C# Tutorials →
C# Tutorial - Generating a unique hardware IDStarted by DeadLine, 31 May 2014 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
Building a "database" in C, need helpStarted by ScareCrawExtended, 07 Nov 2013 ![]() |
|
![]() |
||
![]() Items are multiplying - Cascade comboboxes VB.net + SQLStarted by RiderOfTheli, 04 Jul 2013 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download