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




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com