0

我有一个组合框,我想从 sql server 数据库中填充两列。我的代码是:

Dim cmd As New SqlCommand("Select hospno,hospno + '--- ' + name as pn from Patient order by hospno", cnn)
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
da.Fill(dt)
If dt.Rows.Count > 0 Then
    cbohospno.ValueMember = "hospno"
    cbohospno.DisplayMember = "pn"
    cbohospno.DataSource = dt
Else
    MessageBox.Show("Empty")
End If

运行时,显示的是组合框name而不是hospno. 如何hospno在组合框中显示?

4

1 回答 1

1

将 DisplayMember 设置为“hospno”,你应该没问题。DisplayMember 是显示的,ValueMember 是您获得组合框项目值时获得的值。

于 2013-08-28T14:29:42.503 回答