.NETGURU
retrive a single record and bind it to a text box
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-sqlclient' list.


Nishat Syed
-- Moved from [aspngdata] to [ngfx-sqlclient] by Marcie Jones <Click here to reveal e-mail address> --

How do I retrive a single record and bind it to a text box. Whenever I am
trying to use SqlDataReader, it gives me an error that "Invalid attempt to
read when no data is present" The code that I am using is
Dim dr As SqlDataReader = med.GetFewMedium(theID)
Dim snCount = 0 'Do db call
Do While dr.Read()
snCount = snCount + 1
Loop
If snCount <> 0 Then
dr.Read()
rate_fig.Text = Trim(CType(dr("medium_id"), String))
dr.Close()
End If

But I I am using the same command for a drop down list, it works fine. The
code for the drop down is

meds_id.DataSource = med.GetFewMedium(theID)
meds_id.DataBind()
meds_id.Items.Insert(0, new ListItem("Select a Medium"))

Where am I going wrong
The "GetFewMedium" is the stored procedure I am calling

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

Reply to this message...
 
    
Tim Musschoot
Hello,

I'm not 100% sure, but this:

Do While dr.Read()
    snCount = snCount + 1
Loop

Will cause the record cursor to go to the end of the recordset. It is
obsolete to try dr.Read() afterwards, because you will be at 'dr.EOF', so
the result will be empty...

Best Regards,
Tim Musschoot
AspFriends Moderation Team
Click here to reveal e-mail address
http://www.aspalliance.com/tim_musschoot

-----Oorspronkelijk bericht-----
Van: Nishat Syed [mailto:Click here to reveal e-mail address]
Verzonden: dinsdag 18 juni 2002 21:03
Aan: ngfx-sqlclient
Onderwerp: [ngfx-sqlclient] retrive a single record and bind it to a
text box

-- Moved from [aspngdata] to [ngfx-sqlclient] by Marcie Jones
<Click here to reveal e-mail address> --

How do I retrive a single record and bind it to a text box. Whenever I am
trying to use SqlDataReader, it gives me an error that "Invalid attempt to
read when no data is present" The code that I am using is
Dim dr As SqlDataReader = med.GetFewMedium(theID)
Dim snCount = 0 'Do db call
Do While dr.Read()
snCount = snCount + 1
Loop
If snCount <> 0 Then
dr.Read()
rate_fig.Text = Trim(CType(dr("medium_id"), String))
dr.Close()
End If

But I I am using the same command for a drop down list, it works fine. The
code for the drop down is

meds_id.DataSource = med.GetFewMedium(theID)
meds_id.DataBind()
meds_id.Items.Insert(0, new ListItem("Select a Medium"))

Where am I going wrong
The "GetFewMedium" is the stored procedure I am calling

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
 
System.Data.SqlClient.SqlDataReader
System.Web.UI.WebControls.ListItem




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification