如何将列表框与文本框连接 [英] how to connect listbox with textbox
本文介绍了如何将列表框与文本框连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了一个文本框和列表框,我正在将文本框值存储到数据库表中,现在我需要使用vb.net编码将表中的文本框项列出到列表框中. h2_lin>解决方案
非常简单.您可以使用DataReader对象
完成此操作 我假设您正在使用Access数据库.
Dim objda As OleDbDataAdapter = 新 OleDbDataAdapter Dim dr As OleDbDataReader objda.SelectCommand = 新建 OleDbCommand objda.SelectCommand.Connection = Con ' 连接对象 objda.SelectCommand.CommandText = " 尝试 dr = objda.SelectCommand.ExecuteReader ' 执行查询 捕获,例如 As OleDb.OleDbException MessageBox.Show(ex.ToString)' 提供错误消息 结束 尝试 而博士读' 读取DataReader项 ListBox1.Items.Add(dr.Item( 0 ))' 结束 同时 dr.Close()' 关闭DataReader对象
在Button_Click事件上添加此代码. :)
hi , i had created a textbox and listbox , i am storing the text box values to the database table , now i need to list the textbox items in the table to the listbox using vb.net coding .
解决方案
It''s very simple.You can do this using DataReader object
I assume that you are using Access DataBase.
Dim objda As OleDbDataAdapter = New OleDbDataAdapter Dim dr As OleDbDataReader objda.SelectCommand = New OleDbCommand objda.SelectCommand.Connection = Con 'Connection Object objda.SelectCommand.CommandText = "Select FieldName FROM TableName" Try dr = objda.SelectCommand.ExecuteReader 'Exectuing query Catch ex As OleDb.OleDbException MessageBox.Show(ex.ToString) 'Providing Error Message End Try While dr.Read 'Reading DataReader Items ListBox1.Items.Add(dr.Item(0))'Adding these Items Into ListBox End While dr.Close() 'Closing DataReader Object
Add this code on Button_Click Event. :)
这篇关于如何将列表框与文本框连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文