Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have searched from the internet
as i am trying to create a system that doesnt use the databinding source

is it possible to fetch data from ms access and display it in the vb textbox by code?

What I have tried:

dbprovider = "PROVIDER = microsoft.jet.OLEDB.4.0;"
      dbsource = (" Data Source = C:\Users\SEUN\Desktop\Addressbook.mdb")
      con.ConnectionString = dbprovider & dbsource

      Dim cmd As New OleDb.OleDbCommand("SELECT FirstName FROM tblContacts", con)


      con.Open()

      Dim sdr As OleDb.OleDbDataReader = cmd.ExecuteReader

      While sdr.Read()

          ComboBox1.Items.Add(sdr.Item("FirstName").ToString)

      End While

      con.Close()
Posted
Updated 23-Nov-22 17:59pm
Comments
Richard MacCutchan 24-Nov-22 4:16am    
You would need a separate textbox for each row returned from the database.

1 solution

1. You have to learn how to display the data on a textbox control.
We do it by setting the property Text ob object textbox.
For example.

VB
txtName.Text = "John"



2. You have to learn how to retrieve the data from the database.
In your example, you already have a code to retrieve the firstName column from tblContacts table
using OleDBDataReader.
You can change it to
VB
While sdr.Read()

    txtName.Text = sdr.Item("FirstName").ToString

End While


But the txtName will display the FirstName column of the last record only.
Because every iterative, the txtName.Text will be set by the current iterative sdr.Item("FirstName").ToString

Textbox control is not designed to display the collection of value.

I suggest that you learn a fundamental first before you learn to do a database application.
 
Share this answer
 
Comments
Beginner213456 17-Apr-23 2:57am    
Thank you very much for the advice

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