VB.NET List Box

How can i retrieve records of a column having certain criteria and display the records in a list box? Please help me...

Questions by hemantkumar43

Showing Answers 1 - 9 of 9 Answers

dim con as sqlconnection
con=new sqlconnection("server=visuall;database=urdbname;uid=sa;password=urpassword")
con.open()
dimquerycommand as sqlcommand
dim reader as sqldatareader

querycommand=new sqlcommand("select * from emp",con)
reader=querycommand.executereader()
while(reader.reader())
listbox1.items.add(reader(0).tostring() & " " & reader(1).tostring() )
end while

  Was this answer useful?  Yes

Create a connection object in OLEDB or SQL and set the possible parameters.Create a OLEDB DataAdapter or SQL Data Adapter and populate a dataset through the data adapter object.Then set the values of the Datasource and Display member property with the desired datasource and column.Here is the sample code for SqlConnection.

Dim con as new SqlConnection("server='localhost';uid='sa';pwd='password'; database='Employees')
con.Open()
dim ada as new SqlDataAdapter("select * from empdata",con)
Dim ds as new Dataset
ada.Fill(ds,"Empdata")
ListBox1.DataSource=ds.Tables("Empdata").DefaultView
ListBox1.DisplayMember="Empname"
con.Close()

Get the data from db in list of strings or key value pair

finaldatesource=db calll

With listbox

.datasource=finaldatesource
.datatextfield="EmplyeeNAme"
.datavaluefield="EmplyeeNumber"
end with
EmplyeeNAme, EmployeeNumber are coloumns in DB

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions