SQL DataReader

  • Thread starter Thread starter djozy
  • Start date Start date
D

djozy

I want to fill dropdownlist with data's from SQL Server
database using DataReader and DataBinding
controls.Please, can someone send me a code with wich I
can do this
Thank you
 
If it's a desktop app, you can't bind to it, with the web controls you can.

For the desktop, just use this:

Dim cn As New SqlConnection(modConnection.ConnectStringToJobTracking)

Dim cmd As New SqlCommand()

Dim dr As SqlDataReader

Try

cmd.CommandType = CommandType.StoredProcedure

cmd.CommandText = "FillDeptCombo"

cmd.Connection = cn

If cn.State <> ConnectionState.Open Then cn.Open()

dr = cmd.ExecuteReader

lstFacilities.Items.Clear()

While dr.Read

lstFacilities.Items.Add(dr(0))

End While

dr.Close()



For the web, do the same, but instead of the Dr.Read Loop, just set the list
datasource to the cmd.ExecuteReader and call databind afterward.



HTH,



Bill
 
Thank you for help,but I would like to know how to do that
without using stored procedures, and in C# ASP.NET
application
 
Back
Top