Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Binding two controls to a SqlDataReader
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Binding two controls to a SqlDataReader

 Post Reply Post Reply
Author
jamesb View Drop Down
Newbie
Newbie


Joined: 01 September 2003
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote jamesb Quote  Post ReplyReply Direct Link To This Post Topic: Binding two controls to a SqlDataReader
    Posted: 01 October 2003 at 11:41am

hi, I have two controls on a asp.net page, both of which I want to bind to different columns returned from a stored procedure. I can easily get one of the two to do bind, but not both - the code is as follows:

dim IntId As String
dim sqldata As SqlDataReader
  
IntId="4388"
  
sqldata = SqlHelper.ExecuteReader(connString, "sp_GetWhereHearListFromIntroducerID", IntId)
  
drop_wherehear_list.DataSource = sqldata
drop_wherehear_list.DataValueField = "ad_code"
drop_wherehear_list.DataBind()

Which works fine, but when I add the following code for the second dropdown I get an "Invalid attempt to FieldCount when reader is closed" error:

refid_list.DataSource = sqldata
refid_list.DataValueField = "bs_name"
refid_list.DataBind

The stored procedure returns two columns of data - surely it must be possible to bind another dropdown list to the other column, without having to do another round trip to the server?

Thanks for any help :)

Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 03 October 2003 at 3:22am

I might get my syntax a little mixed up here but here goes!

The Execute Reader method will close the connection it uses after being 'iterated' through the first time.

Therefore when you try to bing to your second list box, the reader has already done its thing and can't be accessed any more.

You'll need to either execute the reader again, or use a container which holds your data for longer (such as the dataset).

Cheers,
Andrew 

There have been many, many posts made throughout the world...
This was one of them.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.