Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 .
Posted
Comments
[no name] 2-Dec-11 0:30am    
create a select statement that would select all textbox items in your database. Then iterate over the result and use the Add method of the ListBox control.

-Ed

1 solution

It's very simple.You can do this using DataReader object
I assume that you are using Access DataBase.
VB
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. :)
 
Share this answer
 
Comments
ANANTH P 2-Dec-11 0:53am    
while dr.read "dr" shows already being used
Manoj K Bhoir 2-Dec-11 1:17am    
Before above code add one line dr.Close().This error comes if Data Reader Object already in used and not Closed Properly.
Member 13081648 24-Mar-17 6:46am    
simple db or rs ka use krke listbox ko access file se kaise connect krte hain

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