我实际上有三个组合框绑定到不同的表。我的标题中出现了这样的错误。贝娄是我的代码:
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"
通过这段代码,我只得到第一个显示查询结果的comboboxt,但是其他两个没有,并显示消息'无法绑定到新值成员。参数名称:value'。请帮忙......
答案 0 :(得分:2)
试试这个:
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"
通过多次为同一数据集调用.Fill()
,您感到困惑。通过只对数据库进行一次往返,这也会表现得更好。
答案 1 :(得分:1)
VisitorID和StaffID不是Select语句的一部分。
答案 2 :(得分:0)
您收到的错误“ ...显示消息'无法绑定到新值成员。参数名称:值'。”可能不是由于.Net代码而是SQL语句您正在使用。我有一个类似的问题,我只选择我需要的值的列。例如:
Select * from tblVisitor;
执行此操作时,您只选择FullName,ID不在数据集中。 所以你需要打电话:
cboVisitor.DataSource = myDataSet.Tables(0)
cboVisitor.DisplayMember = "FullName"
cboVisitor.ValueMember = "VisitorID"
然后这段代码应该可以显示你的记忆:
{{1}}
希望这会有所帮助