Results 1 to 4 of 4

Thread: Cannot bind to the new value member. Parameter name: value

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    58

    Cannot bind to the new value member. Parameter name: value

    Hello code masters,

    Today I have been banging my head in the wall trying to figure this one out.

    I have a combo box filled with values from table A field A
    no issue on that, I am able to populate by filling my dataset with sql query and etc.

    Now the problem is, this combo box should also change selected value based on another combo box coming from a different table, table B WHILE RETAINING THE VALUES FROM TABLE A just in case they wanted to change the selected value from table A to values from table B.


    I have this code which selects data OnIndexChange of combo box from tableA where value = cmb1.value


    On indexchange cmb1 =

    Dim ds As DataSet = SQL.RecOnChange(ojConn, BG) - select Field1 from tableA where field1 = cmb1.value

    ojConn.Close()
    If ds.Tables(0).Rows.Count > 0 Then
    Dim DT As New DataTable()
    DT = ds.Tables(0)
    cmb2.DataSource = DT
    cmb2.DisplayMember = "Field1"
    cmb2.ValueMember = "Field1"



    and this for populating the cmb2 with values on page load:

    Dim ds As DataSet = SQL.PopcmbEquip(ojConn, BG) - sql statement : select field2 from tableB order by field 2

    ojConn.Close()
    If ds.Tables(0).Rows.Count > 0 Then
    Dim DT As New DataTable()
    DT = ds.Tables(0)
    cmb2.DataSource = DT
    cmb2.DisplayMember = "Field2"
    cmb2.ValueMember = "Field2"



    I am getting error:
    Cannot bind to the new value member. Parameter name: value


    I think the error is because I cannot assign two datasource and valuemember to one combo box

    Any inputs will be greatly appreciated.
    Thank you so much in advance.

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,528

    Re: Cannot bind to the new value member. Parameter name: value

    If I understand the issue then one way too go about this is to load all data into a single dataset, that is if there is not a lot of data meaning thousands of records. The load that gets loaded would be sorted via your SQL select statement. You would create a relationship between the two tables after loading the DataSet. From here two BindingSource components would be used to sync the data between the two tables.

    In the following working example this is done with a master-detail where the details table also represents the master into another table (which is more than needed here). Note, I created this for another question and used xml to load the dataset but the same applies for no matter where the data comes from, all that matters is the dataset is loaded with a proper relationship

  3. #3
    Addicted Member
    Join Date
    Oct 2012
    Posts
    166

    Re: Cannot bind to the new value member. Parameter name: value

    Boosting up kevininstructor's post, by loading up all the database structure into a single dataset, then all you need to is simply create 2 sql queries on the table you're trying to populate your data into.
    Then when you select an index on cmb1 you execute query 1 and after selecting index for cmb2, you execute query 2, probably returning even less records (a sort of record filtering refinement per say).

    I use this method on most of my projects and it's very good for getting information in a fast and reliable way.

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    58

    Re: Cannot bind to the new value member. Parameter name: value

    Quote Originally Posted by Simbiose View Post
    Boosting up kevininstructor's post, by loading up all the database structure into a single dataset, then all you need to is simply create 2 sql queries on the table you're trying to populate your data into.
    Then when you select an index on cmb1 you execute query 1 and after selecting index for cmb2, you execute query 2, probably returning even less records (a sort of record filtering refinement per say).

    I use this method on most of my projects and it's very good for getting information in a fast and reliable way.
    I am actually thinking of having two SQL statements

    1. Select field1 from table A - this to populate the dropdownlist
    2. Select field1 from table B where field1 = othercombobox selected value.

    Thing is, I am not sure how to do that. I tried so many things but kept on telling me I cannot assign two datasource for 1 dropdownlist.



    This is in my onpageload event

    da.SelectCommand = New SqlCommand("Select Equipment from tblEquipmentMaster order by Equipment", con)
    ds.Tables.Add(New DataTable("Table1"))
    ds.Tables.Add(New DataTable("Table2"))
    da.Fill(ds.Tables(0))
    cmbEquip.DisplayMember = "Equipment"
    cmbEquip.ValueMember = "Equipment"
    cmbEquip.DataSource = ds.Tables(0)

    and this on selected indexchange of combobox


    da.SelectCommand = New SqlCommand("Select EquipmentMaster from tblBuildMaster where BuildNum = " & cmbBuildNum.SelectedValue(), con)
    'ds.Tables.Add(New DataTable("Table1"))
    'ds.Tables.Add(New DataTable("Table2"))
    ds.Tables(0).Clear()
    da.Fill(ds.Tables(0))

    cmbEquip.DataSource = Nothing
    cmbEquip.DisplayMember = "EquipmentMaster"
    cmbEquip.ValueMember = "EquipmentMaster"
    cmbEquip.DataSource = ds.Tables(0)
    cmbEquip.SelectedValue = ds.Tables(0)
    Attached Images Attached Images  

Tags for this Thread

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