如何从访问数据库中搜索和显示文本框或列表框数据存储上的结果? [英] how to search and diplay the resulte on textbox or listbox data store from access database?

查看:55
本文介绍了如何从访问数据库中搜索和显示文本框或列表框数据存储上的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在从访问数据库中检索的文本框或列表框中显示数据?

display data on textbox or listbox that retrieve from access database?

推荐答案

您需要使用SQL Reader在Textbox或ListBox中显示数据,请尝试以下代码:

You need to use SQL Reader to Show Data in Textbox or ListBox, Try the below code:
Dim CN As New OleDbConnection("You Connection Strting")
            CN.Close()
            Dim myCommand1 As New OleDbCommand("SELECT * from MyTable Where ID=@id", CN)
            myCommand1.Parameters.Add(New OleDbParameter("id", OleDbType.VarChar)).Value = TxtId.Text
            CN.Open()
            Dim myReader As OleDbDataReader
            myReader = myCommand1.ExecuteReader()
            myReader.Read()
                    If myReader.HasRows Then
 Textbox1.Text = myReader2("Name").ToString
Textbox2.Text = myReader2("Address").ToString



为了绑定列表框,你可以使用数据集。


And for to bind the Listbox, you can use Dataset.

Dim cn As New OleDbConnection("Your Connection String")
           cn.Open()
           Dim qry As String = "SELECT ID,Name FROM  MyTable"
           Dim adp As New OleDbDataAdapter(qry, cn)
           Dim ds As New DataSet
           adp.Fill(ds, "MyTable")
            ListBox1.DataSource = ds
            ListBox1.DataTextField = "Name"
            ListBox1.DataValueField = "ID"
            ListBox1.DataBind()







请不要忘记标记答案。




Please dont forget to mark as answer.


这篇关于如何从访问数据库中搜索和显示文本框或列表框数据存储上的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆