Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2004, 09:31 PM
Authorized User
 
Join Date: Jan 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rathbird
Default Problem reading DataReader after Databind

I have a group of data items that I'm displaying using a repeater. Two of the data items are the same (date and employee) for all records. I want to pull these out of the report and just show them once in my table. I've tried using the <%# DataBinder.Eval(Container.DataItem, "date")%> in the Repeater header, but it does not show up.

I've taken these fields out of the repeater and set up two labels (consultdate and consultemp). Now I've tried to assign the values to these using the following code:

SqlConnection1.Open()
   GetConsultHist.Parameters.Item("@pid").Value = ptid.Text

   Dim myHistReader As SqlDataReader = GetConsultHist.ExecuteReader

   If myHistReader.Read Then
      consultdate.Text = myHistReader.Item(1)
      consultemp.Text = myHistReader.Item(0)
   Else
      consultdate.Text = "data not available"
   End If

   ConsultRepeater.DataSource = myHistReader
   ConsultRepeater.DataBind()

SqlConnection1.Close()

The problem with this solution is that the data in the repeater is missing the first record. I solved that by setting the datasource and databinding above the myHistReader.read, but doing that always returns "data not available" although there are clearly records on the page.

So, I'm thinking that I need to reset the reader before I do a .read, but I don't know how to do this.

Any hints would be greatly appreciated!

 
Old March 10th, 2004, 05:53 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

DataReaders are forward-only read-only. Also known as firehose data providers. Once you open the hose, you can't put the water back into it: i.e. once you have read any record (with either .Read() or by binding to a control) you can't go back. You could solve this by using a dataset and then access the datatable for the two values and still be able to bind the table to the repeater.

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
DataReader problem nalla ASP.NET 1.0 and 1.1 Professional 6 February 7th, 2006 06:07 AM
Problem with datareader ashokparchuri ADO.NET 2 May 13th, 2005 04:32 AM
DataBind/DataSource problem liorlankri ADO.NET 3 November 10th, 2004 09:15 AM
DataBind Problem liorlankri ADO.NET 3 November 2nd, 2004 04:13 PM
Reading CSV in DataReader salimgbelim ADO.NET 0 November 3rd, 2003 07:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.