Hello, i need a code to show data from database into textbox
i have this request
"select count(*) from table"
i work with access database andi want show the result in textbox
pleaase help

Hi
You should look up the OLEDBConnection Class to find out how to run SQL against a Database through OLEDB (as opposed to SQL Server).

To connect to the Access database through the OLEDBConnection Class, you will need a connection string to connect to Access

This should get you started - there are loads of examples of code both in MSDN and other VB.NET sites as well as examples and snippits on this very forum.

thank you kRod, G WAddel, i know how to link vb.net with access database, but i can't show data from database into textbox, since i can show data in datagreadview.thank you for help

What value are you trying to put into the textbox? What column and row in the underlying dataSource is it in ? Do you need to search the dataSource for the value or does your query select a single value --- 'Command.ExecuteScalar' As you can see there is a lot of info we would need to answer your question. Showing the code that retrieves the data would help alot....

my database contains a table of products with five columns: ID, Reference, quantity,the turnover, and categories, I want to show in textboxes the number of references that match a category, the sum of quantities.ofcourse my query select a single value.
I just write the class of connection I have not write any code for textboxes

TextBox1.Text = Cstr(Value from the Query)

Hello kRod, I found the solution, that's it: the message box return the result of my query, but the problem that i can't retrieve this result in my texbox, when my program is running, an error message appears: "impossible to change the property Connection String"

Private Sub TextBox4_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
        dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
        dbSource = "Data Source=C:\Users\Gayzlein\Documents\Gestion.accdb"
        con.ConnectionString = dbProvider & dbSource
        con.Open()
               Dim cmd As New OleDb.OleDbCommand("select count(*) from Categories1 where classe='A'", con)
        Dim count As Int32 = CInt(cmd.ExecuteScalar)
        MsgBox(count)
        TextBox4.Text = cstr(count)
    con.Close()

Thanks kRod

Yes, I found it, I just have to write the same code in "private sub form_load.." Thanks for help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.