Solved

Sql Data Reader not displaying return Values

Posted on 2008-10-29
7
140 Views
Last Modified: 2010-04-21
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

0
Comment
Question by:HarleySkater
  • 5
7 Comments
 
LVL 20

Accepted Solution

by:
brwwiggins earned 450 total points
ID: 22833774
You need a while loop around your data reader. See this example http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=1
0
 
LVL 4

Assisted Solution

by:nasserd
nasserd earned 50 total points
ID: 22833841
brwwiggins seems to be right; I've encountered the same behavior and solution a while back.
0
 
LVL 1

Author Comment

by:HarleySkater
ID: 22833956
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

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:HarleySkater
ID: 22834008
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

0
 
LVL 1

Author Comment

by:HarleySkater
ID: 22834028
My guess is the problem is starting here ----   Response.Write(dr("Field"))

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

0
 
LVL 1

Author Comment

by:HarleySkater
ID: 22834100
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

0
 
LVL 1

Author Closing Comment

by:HarleySkater
ID: 31511297
THank YOUUUUu BRWWIGGINS
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server - Set Value of Multiple Fields in One Query 10 22
SQL Insert parts by customer 12 31
always on switch back after failover 2 31
Return 0 on SQL count 24 28
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now