PC Review


Reply
Thread Tools Rate Thread

DataReader error

 
 
tshad
Guest
Posts: n/a
 
      23rd Jun 2005
I have a dataReader that I am trying to use with datalist that works fine
with my dropdown but gives me an error when binding with the datalist.

The error is:

Invalid attempt to FieldCount when reader is closed

The code is:

**********************************************************
Dim myDbObject as new DbObject()
Dim DBReader As SqlDataReader

Dim parameters As SqlParameter () = { _
New SqlParameter("@Email",SqlDbType.VarChar,45) }

parameters(0).value = session("Email")

dbReader = myDbObject.RunProcedure("GetLetters", parameters)

DataList1.DataSource=dbReader
DataList1.databind()
*************************************************************

The myDbObject.RunProcedure is my object that fills a datareader from the
Stored Procedure "GetLetters".

The dropdown list worked fine when I had:

StoredLetters.DataSource=dbReader
StoredLetters.DataValueField="LetterID"
StoredLetters.DataTextField= "LetterTitle"
StoredLetters.databind()

I just changed the datasource area and assumed this would work, but it
doesn't.

The datalist is:

<aspataList ID="DataList1" RepeatColumns="4"
RepeatDirection="Horizontal" runat="server" >
<ItemTemplate><%# Container.DataItem("LetterTitle") %>
</ItemTemplate>
</aspataList>

Very simple - I would have thought.

What would cause that problem?

It is virtually identical code, except for the dropdownlist vs the Datalist.

Thanks,

Tom




 
Reply With Quote
 
 
 
 
tshad
Guest
Posts: n/a
 
      23rd Jun 2005
"tshad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a dataReader that I am trying to use with datalist that works fine
> with my dropdown but gives me an error when binding with the datalist.
>
> The error is:
>
> Invalid attempt to FieldCount when reader is closed
>
> The code is:
>
> **********************************************************
> Dim myDbObject as new DbObject()
> Dim DBReader As SqlDataReader
>
> Dim parameters As SqlParameter () = { _
> New SqlParameter("@Email",SqlDbType.VarChar,45) }
>
> parameters(0).value = session("Email")
>
> dbReader = myDbObject.RunProcedure("GetLetters", parameters)
>
> DataList1.DataSource=dbReader
> DataList1.databind()
> *************************************************************
>
> The myDbObject.RunProcedure is my object that fills a datareader from the
> Stored Procedure "GetLetters".
>
> The dropdown list worked fine when I had:
>
> StoredLetters.DataSource=dbReader
> StoredLetters.DataValueField="LetterID"
> StoredLetters.DataTextField= "LetterTitle"
> StoredLetters.databind()
>
> I just changed the datasource area and assumed this would work, but it
> doesn't.
>
> The datalist is:
>
> <aspataList ID="DataList1" RepeatColumns="4"
> RepeatDirection="Horizontal" runat="server" >
> <ItemTemplate><%# Container.DataItem("LetterTitle") %>
> </ItemTemplate>
> </aspataList>
>
> Very simple - I would have thought.
>
> What would cause that problem?
>
> It is virtually identical code, except for the dropdownlist vs the

Datalist.
>


I tried to modify the subroutine to do a the dataread directly instead of
from my object and got the same error.

********************************************************************
Sub CheckStoredCoverLetters()
Dim dbReader As SqlDataReader

Dim ConnectionString as String
=System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRIN
G_ftol")
Dim objConn as New SqlConnection (ConnectionString)
Dim CommandText as String = "GetLetters"
Dim objCmd as New SqlCommand(CommandText,objConn)
objCmd.CommandType = CommandType.StoredProcedure
with objCmd.Parameters
.Add("@Email",SqlDbType.VarChar,45).value = session("Email")
end with
objConn.Open()

DataList1.DataSource=objCmd.ExecuteReader
DataList1.databind()
********************************************************************

The DataList is:

<aspataList ID="DataList1" RepeatColumns="4" RepeatDirection="Horizontal"
runat="server" >
<ItemTemplate><%# Container.DataItem("LetterTitle") %>
</ItemTemplate>
</aspataList>

This should be pretty straight forward.

What is this error telling me?

Thanks,

Tom


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to process datareader nulls coming from datareader? JB Microsoft C# .NET 4 3rd Nov 2008 12:56 AM
Strange Datareader error Johnny Jörgensen Microsoft C# .NET 3 2nd May 2007 06:10 PM
DataReader Error When there is no record! Kivanç Karaca Microsoft ASP .NET 5 13th Oct 2004 01:33 PM
DataReader Error pete Microsoft ADO .NET 1 25th Jul 2003 12:33 AM
datareader.getstring(0) error Nakhi Microsoft ASP .NET 3 15th Jul 2003 07:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:51 AM.