Link to home
Start Free TrialLog in
Avatar of HarleySkater
HarleySkaterFlag for United States of America

asked on

Sql Data Reader not displaying return Values

I am having trouble getting data returned from a Stored Procedure to display in a Repeater.

I know the Stored Procedure is working and I know it is returning data, I tested it with a label, its shown in the code snippet.

how do you get returned data to display in the repeater?

Thanks :D

------ ASPX Code
 
    <asp:Label ID="UserIdLabel" runat="server" Text=""></asp:Label>
   
   <hr />
    
<asp:Repeater id="ListProfiles" runat="server" EnableViewState="False">     
    <HeaderTemplate>
    </HeaderTemplate>
    <ItemTemplate>
                <%# DataBinder.Eval(Container.DataItem, "UserId") %>
    </ItemTemplate>
 
</asp:Repeater>
 
------ Behind VB Code
                       Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("AGConnectionString").ConnectionString)
 
                Using myCommand As New SqlCommand("AGProfileSearchName", myConnection)
 
                    myCommand.CommandType = CommandType.StoredProcedure
                    myConnection.Open()
 
                    myCommand.Parameters.AddWithValue("@SearchName", SearchName)
 
                    Dim dr As SqlDataReader = myCommand.ExecuteReader()
                    dr.Read()
 
                    UserIdLabel.Text = dr("UserId").ToString().Trim()
 
 
                    ListProfiles.DataSource = dr
                    ListProfiles.DataBind()
 
                    dr.Close()
 
                    myConnection.Close()
                End Using
            End Using

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of brwwiggins
brwwiggins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HarleySkater

ASKER

I'm sorry but I got the same result!   :*(  I will paste my updated code




---- ASPX WEBFORM
 
    <asp:Label ID="UserIdLabel" runat="server" Text=""></asp:Label>
   
   <hr />
    
<asp:Repeater id="ListProfiles" runat="server" EnableViewState="False">     
    <HeaderTemplate>
    </HeaderTemplate>
    <ItemTemplate>
                <%# DataBinder.Eval(Container.DataItem, "UserId") %>
                <%# DataBinder.Eval(Container.DataItem, "ProfileName") %>
                <%# DataBinder.Eval(Container.DataItem, "RealName") %>
                <%# DataBinder.Eval(Container.DataItem, "Age") %>
    </ItemTemplate>
 
</asp:Repeater>
 
 
 
 
----- VB BEHIND CODE
 
            Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("AGConnectionString").ConnectionString)
 
                Using myCommand As New SqlCommand("AGProfileSearchName", myConnection)
 
                    myCommand.CommandType = CommandType.StoredProcedure
                    myConnection.Open()
 
                    myCommand.Parameters.AddWithValue("@SearchName", SearchName)
 
                    Dim dr As SqlDataReader = myCommand.ExecuteReader()
 
 
 
                    While (dr.Read())
                        UserIdLabel.Text = dr("UserId").ToString().Trim()
 
                        Response.Write(dr("UserId"))
 
                        'Spacing
                        Response.Write("   ")
 
                        Response.Write(dr("ProfileName"))
 
                        'Spacing
                        Response.Write("   ")
 
                        Response.Write(dr("RealName"))
 
                        'Spacing
                        Response.Write("   ")
 
                        Response.Write(dr("Age"))
 
                        'New Line
                        Response.Write("<br>")
 
 
 
 
                    End While
 
 
                    ListProfiles.DataSource = dr
                    ListProfiles.DataBind()
 
                    dr.Close()
 
                    myConnection.Close()
                End Using
            End Using

Open in new window

wow now I even tried this and its not working
 Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("AGConnectionString").ConnectionString)
 
 
                Using myCommand As New SqlCommand("SELECT UserId, ProfileName, RealName, Age from ag_profiles", myConnection)
                    myConnection.Open()
 
                    
                    Dim dr As SqlDataReader = myCommand.ExecuteReader()
 
 
 
                    While (dr.Read())
                        UserIdLabel.Text = dr("UserId").ToString().Trim()
 
                        Response.Write(dr("UserId"))
 
                        'Spacing
                        Response.Write("   ")
 
                        Response.Write(dr("ProfileName"))
 
                        'Spacing
                        Response.Write("   ")
 
                        Response.Write(dr("RealName"))
 
                        'Spacing
                        Response.Write("   ")
 
                        Response.Write(dr("Age"))
 
                        'New Line
                        Response.Write("<br>")
 
 
 
 
                    End While
 
 
                    ListProfiles.DataSource = dr
                    ListProfiles.DataBind()
 
                    dr.Close()
 
                    myConnection.Close()
                End Using
            End Using

Open in new window

My guess is the problem is starting here ----   Response.Write(dr("Field"))

How do you get the returned data to display in the repeater?

OK!!!! GOT THIS WORKING
            Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("AGConnectionString").ConnectionString)
 
                'Using myCommand As New SqlCommand("AGProfileSearchName", myConnection)
                Using myCommand As New SqlCommand("SELECT UserId, ProfileName, RealName, Age from ag_profiles", myConnection)
                    'myCommand.CommandType = CommandType.StoredProcedure
 
                    myConnection.Open()
 
                    'myCommand.Parameters.AddWithValue("@SearchName", SearchName)
 
                    Dim dr As SqlDataReader = myCommand.ExecuteReader()
 
                    ListProfiles.DataSource = dr
 
                    While (dr.Read())
 
 
 
 
                        ListProfiles.DataBind()
 
                    End While
 
                    dr.Close()
 
                    myConnection.Close()
                End Using
            End Using

Open in new window

THank YOUUUUu BRWWIGGINS