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:

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

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

Re: DataReader error by tshad

tshad
Thu Jun 23 00:39:44 CDT 2005

"tshad" <tscheiderich@ftsolutions.com> wrote in message
news:O0IPsV5dFHA.1040@TK2MSFTNGP10.phx.gbl...
> 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:
>
> <asp:DataList ID="DataList1" RepeatColumns="4"
> RepeatDirection="Horizontal" runat="server" >
> <ItemTemplate><%# Container.DataItem("LetterTitle") %>
> </ItemTemplate>
> </asp:DataList>
>
> 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:

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

This should be pretty straight forward.

What is this error telling me?

Thanks,

Tom