本文介绍了当我从组合框中选择项目时,如何从数据库填充文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我想要发生的事情:当我从组合框中选择一个项目时,文本框将自动填充数据
当我选择第1列的clientName时,我想用联系人填充文本框,该联系人是客户表的第2列。
我有什么试过:
这是我试过的:
This is what i want to happen: When i select an item from the combobox the textbox will automatically be filled with data
When i select a clientName which is column 1, i want to populate the textbox with contact person which is column 2 of the Clients table.
What I have tried:
this is what i tried:
'Populate the combox with clientnames from clients '
Try
connection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nikko Jaze Fabellon\Documents\ASRASIM.accdb")
connection.Open()
ds = New DataSet
tables = ds.Tables
dataAdapter = New OleDbDataAdapter("SELECT [ClientName] from [Clients] where [Status] = 'Active' ", connection)
dataAdapter.Fill(ds, "Clients")
Dim view1 As New DataView(tables(0))
With clientNameText
.DataSource = ds.Tables("Clients")
.DisplayMember = "ClientName"
.ValueMember = "ClientName"
.SelectedIndex = 0
.AutoCompleteMode = AutoCompleteMode.SuggestAppend
.AutoCompleteSource = AutoCompleteSource.ListItems
End With
'This is where i would enter the codes'
With clientNameText
.DisplayMember = "Contact Person"
.ValueMember = "Contact Person"
.DataSource = ds.Tables
End With
cPersonText.DataBindings.Add("", ds.Tables, "")
推荐答案
taAdapter = New OleDbDataAdapter("SELECT [ClientName],[Contact Person] from [Clients] where [Status] = 'Active' ", connection)
.
.
.
.DisplayMember = "ClientName"
.ValueMember = "Client Person"
.
.
.
然后,您可以参考所选行的ValueMember来填充文本框
You can then refer to the ValueMember of the selected row to populate your textbox
这篇关于当我从组合框中选择项目时,如何从数据库填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!