Results 1 to 5 of 5

Thread: [RESOLVED] [2005] What's wrong with my combo?

  1. #1

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Resolved [RESOLVED] [2005] What's wrong with my combo?

    This is how I'm binding my combobox:

    Code:
        Public Sub carregaPais()
            Me.ComboPais.DataSource = AbreDataSet("Select * from Paises", "Pais")
            Me.ComboPais.DisplayMember = "Pais"
            Me.ComboPais.ValueMember = "IDPais"
        End Sub
    
    
        Function AbreDataSet(ByVal strSQL As String, ByVal Tabela As String) As DataSet
            Dim ds As DataSet
            Dim DataAdapt As Odbc.OdbcDataAdapter
            Dim conn As New Odbc.OdbcConnection(sConnString)
    
            DataAdapt = New Odbc.OdbcDataAdapter(strSQL, sConnString)
            ds = New DataSet()
            conn.Open()
    
            DataAdapt.Fill(ds, Tabela)
            Return ds
            ds = Nothing
        End Function
    My combo returns this error:
    Cannot bind to the new value member.
    Parameter name: value

    What am I doing wrong?
    Thank you.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] What's wrong with my combo?

    You're binding your ComboBox to a DataSet and that DataSet has no property named "IDPais". Nowhere are you telling the ComboBox that it's supposed to get its data from the DataTable named "Pais".

    In fact, your DataSet is completely pointless. Gneerally a DataSet with one DataTable in it is useless That's like creating an array to store a single string, except even more inefficient.

    If all you want is one DataTable then all you need to create is one DataTable:
    VB.NET Code:
    1. Public Sub carregaPais()
    2.         Me.ComboPais.DataSource = AbreDataTable("Select * from Paises", "Pais")
    3.         Me.ComboPais.DisplayMember = "Pais"
    4.         Me.ComboPais.ValueMember = "IDPais"
    5.     End Sub
    6.  
    7.  
    8.     Function AbreDataTable(ByVal strSQL As String, ByVal Tabela As String) As DataTable
    9.         Dim conn As New Odbc.OdbcConnection(sConnString)
    10.         Dim comm As New Odbc.OdbcCommand(strSQL, conn)
    11.  
    12.         conn.Open()
    13.  
    14.         Dim rdr As Odbc.OdbcDataReader = comm.ExecuteReader()
    15.         Dim tbl As New DataTable(Tabela)
    16.  
    17.         tbl.Load(rdr)
    18.         rdr.Close()
    19.         conn.Close()
    20.         Return tbl
    21.     End Function
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005] What's wrong with my combo?

    Hi jmcilhinney.
    Thank you for the reply but steel have the same error.
    What should do next?
    Thank you.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] What's wrong with my combo?

    If you've followed my suggestion and it still doesn't work then your DataTable mustn't have a column named "IDPais". Note that both DisplayMember and ValueMember are case-sensitive. An invalid DisplayMember will simply be ignored but an invalid ValueMember will always throw an exception.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005] What's wrong with my combo?

    Ok. It was the case sensitive!
    Now it's working.
    Thank you once again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width