0

I actually have three combobox bind to diffrent table. and I got such the error in my title. Bellow are my codes:

myCommand = New SqlCommand("SELECT (FirstName +' '+ LastName) AS FullName FROM tblVisitor", myConnection)
   myAdapter = New SqlDataAdapter(myCommand)
   myAdapter.Fill(myDataSet, "tblVisitor")
   cboVisitor.DataSource = myDataSet.Tables(0)
   cboVisitor.DisplayMember = "FullName"
   cboVisitor.ValueMember = "VisitorID"

   'my another combobox
   myCommand = New SqlCommand("SELECT BookCode FROM tblBook", myConnection)
   myAdapter = New SqlDataAdapter(myCommand)
   myAdapter.Fill(myDataSet, "tblBook")
   cboBookCode.DataSource = myDataSet.Tables(1)
   cboBookCode.DisplayMember = "BookCode"
   cboBookCode.ValueMember = "BookCode"  'where BookCode is the pk-column of the tblBook

   'my another combobox
   myCommand = New SqlCommand("SELECT (FirstName +' '+ LastName) AS StaffFullName FROM tblStaff", myConnection)
   myAdapter = New SqlDataAdapter(myCommand)
   myAdapter.Fill(myDataSet, "tblStaff")
   cboStaff.DataSource = myDataSet.Tables(2)
   cboStaff.DisplayMember = "StaffFullName"
   cboStaff.ValueMember = "StaffID"

Through this code, i got only the first comboboxthat display the query result, but the other two do not, and display the message 'Cannot bind to the new value member. Parameter name: value'. Please help...

3 Answers 3

2

Try this:

myCommand = New SqlCommand("SELECT (FirstName +' '+ LastName) AS FullName FROM tblVisitor;SELECT BookCode FROM tblBook;SELECT (FirstName +' '+ LastName) AS StaffFullName FROM tblStaff", myConnection)
   myAdapter = New SqlDataAdapter(myCommand)
   myAdapter.Fill(myDataSet)

   cboVisitor.DataSource = myDataSet.Tables(0)
   cboVisitor.DisplayMember = "FullName"
   cboVisitor.ValueMember = "VisitorID"

   'my another combobox
   cboBookCode.DataSource = myDataSet.Tables(1)
   cboBookCode.DisplayMember = "BookCode"
   cboBookCode.ValueMember = "BookCode"  'where BookCode is the pk-column of the tblBook

   'my another combobox
   cboStaff.DataSource = myDataSet.Tables(2)
   cboStaff.DisplayMember = "StaffFullName"
   cboStaff.ValueMember = "StaffID"

You were confusing things by calling .Fill() multiple times for the same dataset. This will also perform better by only making one round-trip to the database.

2
  • Oh - @Vivek spotted it better. But I still think you should also make the changes I suggested here, to avoid unneeded extra trips to the db. Jun 30, 2011 at 18:00
  • 1
    guy, it still does not work, it does display the same error message. Jun 30, 2011 at 18:14
1

VisitorID and StaffID are not part of the Select statements.

1
  • 1
    guy, it still does not work, it does display the same error message Jun 30, 2011 at 18:15
0

The error your receiving " ...display the message 'Cannot bind to the new value member. Parameter name: value'. " is probably not due to the .Net code rather the SQL statement you are using. I had a simlar problem where I was only select only the column of the value I needed. in example:

Select FullName from tblVisitor;

When you do this you are only selecting FullName the ID isn't in your dataset. So you Would need to call:

Select * from tblVisitor;

Then this code should work to display your memnbers:

cboVisitor.DataSource = myDataSet.Tables(0) cboVisitor.DisplayMember = "FullName" cboVisitor.ValueMember = "VisitorID"

hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.