使用组合列访问数据库填充Combobox

时间:2018-03-25 02:34:25

标签: vb.net combobox multiple-columns access items

如何组合我的访问数据库“contacts.accdb”填充组合框中的“名字”“姓氏”列?我已将dataset + datagridview加载到项目中的另一个表单中。

1 个答案:

答案 0 :(得分:1)

一个简单但完整的例子:

Dim con as New OledbConnection = connectionstringhere
Dim cmd as New OleDbCommand("Select * from tablenamehere",con)
Dim dr as OledbDataReader=cmd.ExecuteReader
While dr.read
Dim FnameAndLname as string = dr(0).ToString + " " + dr(1).ToString 'Assuming the FirstName is the 1st and the LastName is the 2nd Column of the table
MyConboBox.Items.Add(FnameAndLname)
End while

希望这会有所帮助:)