2011-06-30 63 views
0

當我試圖從sql數據庫中選擇數據時,我得到了System.Data.DataRowView。這些是我的代碼:vb.net - 當試圖從sql數據庫中選擇數據時,combobox顯示System.Data.DataRowView當試圖從sql數據庫中選擇數據時

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

我得到了上述錯誤。請幫忙。

回答

2

您的SelectCommand既不返回列LastName也不返回FirstName。您只返回一列(兩列的串聯)。

所以這應該工作:

myCommand = New SqlCommand("SELECT VisitorID, LastName, FirstName, (FirstName +' '+ LastName)As FullName FROM tblVisitor", myConnection) 
myAdapter = New SqlDataAdapter(myCommand) 
myAdapter.Fill(myDataSet, "tblVisitor") 
cboName.DataSource = myDataSet.Tables(0) 
cboName.DisplayMember = "FullName" 
cboName.ValueMember = "VisitorID" 'change to the correct pk-column' 
+0

,因爲我有3個組合框限制到3個不同的表格,並且在成功檢索到第一個組合框之後,其他兩個組合框出現錯誤'無法綁定到新值成員。參數名稱:值' –

0

您需要設置ValueMember以及DisplayMember

+0

哎,帥哥。它也行不通,你能指導我嗎? –

相關問題