Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Need help

Id multiple columns combobox

  • Please log in to reply
4 replies to this topic

#1 Imless

Imless

    CC Regular

  • Member
  • PipPipPip
  • 44 posts
  • Location:CDOC, Philippines
  • Learning:C, Java, C++, C#, PHP, (Visual) Basic, JavaScript, PL/SQL, Visual Basic .NET, Transact-SQL, VBScript

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.
  • 0

#2 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

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.

System.EventArgs) Handles ComboBox1.SelectedIndexChanged
 If (ComboBox1.SelectedValue <> Nothing) 
    Label1.Text = ComboBox1.SelectedValue.ToString()
End Sub

  • 0

#3 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash

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
  • 0
My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth

#4 Imless

Imless

    CC Regular

  • Member
  • PipPipPip
  • 44 posts
  • Location:CDOC, Philippines
  • Learning:C, Java, C++, C#, PHP, (Visual) Basic, JavaScript, PL/SQL, Visual Basic .NET, Transact-SQL, VBScript

Posted 13 September 2012 - 10:23 AM

how to put a breakpoint?
  • 0

#5 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash

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.
  • 1
My Blog: http://forum.codecal...699-blog-77241/
"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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download