473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

SQL DataReader

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
Nov 15 '05 #1
2 1358
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.ConnectStringToJobTrac king)

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

"djozy" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
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

Nov 15 '05 #2
Thank you for help,but I would like to know how to do that
without using stored procedures, and in C# ASP.NET
application
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
6
by: Ravi | last post by:
Hi, I am not able to understand why a datareader needs a connection to the DB all the time. Here is what I tried. Sqlcommand cmd = ("select * from table1",con) // where con is the connection...
5
by: Jason Huang | last post by:
Hi, Is it possible to bind DataReader to a DataGrid in C# windows form? And how? And can we update data in a DataSet by using the DataReader? Thanks for help. Jason
12
by: Thomas Scheiderich | last post by:
I have 2 dropdowns that are exactly the same and I don't want to re-read for each. Is there a way to do something like below where I read the data, bind to depCity1 and then bind to destCity2. ...
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
2
by: Andrei Pociu | last post by:
In a typical ASP .NET Web Application (website), I'm currently using a class where I declare some public static objects. For example there's the place where I initialize the SqlConnection. Also...
1
by: Brent | last post by:
I'm having a hard time wrapping my head around how to build a multi-dimensional array of n length out of a DataReader loop. Take this pseudo-code: ======================================= public...
7
by: Varangian | last post by:
Hi all, the question I want to ask if the conversion of a DataReader to a Table looping through the DataReader is better than using the Fill Method of the DataAdapter... I'm asking because...
7
by: Diffident | last post by:
Hello All, I would like to use DataReader based accessing in my Data Access Layer (DAL). What is considered to be a best practice while returning from a DAL method that executes a query and...
3
by: Johnny Jörgensen | last post by:
I've got an error that I simply cannot locate: I've got a form in which I use a datareader object to read information from a db. After the read, I close the reader and I dispose of both the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.