Click here to Skip to main content
16,005,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
display data on textbox or listbox that retrieve from access database?
Posted
Comments
Pheonyx 18-Dec-13 7:42am    
Care to expand your "question".
What are you trying to do? What have you tried? What problems are you facing?
What sort of application is this?

1 solution

You need to use SQL Reader to Show Data in Textbox or ListBox, Try the below code:
VB
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.
VB
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900