Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a stored procedure that contains 3 select queries.In C# code I have called this stored procedure and the result is stored in a dataset. In aspx form I have used repeater control and in that there are controls to which the result should be binded. But only the first variable i.e, "question" is binded and other two are not.
-------------------------------------------------------------------------------
Stored procedure code:
-------------------------------------------------------------------------------
CREATE PROCEDURE Sp_GetUserStat
@RegId int
AS
SELECT COUNT(*) AS question FROM tblQuestion WHERE RegID=@RegId ;
SELECT COUNT(*) AS answer FROM tblAnswer WHERE RegID=@RegId;
SELECT Points AS point FROM tblPoints WHERE RegID=@RegId;
RETURN 0
-------------------------------------------------------------------------------
C# code : GetUserStat(LogicLayer li)
-------------------------------------------------------------------------------
C#
public DataSet GetUserStat(LogicLayer li)
      {
          try
          {
              cmd = new SqlCommand("Sp_GetUserStat", con);
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.AddWithValue("@RegId", li.RegId);
              adp = new SqlDataAdapter(cmd);
              ds = new DataSet();
              adp.Fill(ds, "UserStat");
              return ds;
          }
          catch (Exception)
          {

              throw;
          }
          finally
          {
              cmd.Dispose();
          }
      }

-------------------------------------------------------------------------------
C# code : Get_UserStat(LogicLayer li)
-------------------------------------------------------------------------------
C#
public DataSet Get_UserStat(LogicLayer li)
      {
          return dal.GetUserStat(li);
      }


-------------------------------------------------------------------------------
C# code : CodeBehind
-------------------------------------------------------------------------------
C#
public partial class UserProfile : System.Web.UI.Page
  {
      LogicLayer li = new LogicLayer();

      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              li.RegId = Convert.ToInt32(Session["RegId"]);
              lstUserProfile.DataSource = li.Get_User_Profile(li);
              lstUserProfile.DataBind();
              rptUserStat.DataSource = li.Get_UserStat(li);
              rptUserStat.DataBind();





          }
      }
  }

------------------------------------------------------
ASPX code:
------------------------------------------------------
ASP.NET
<asp:Repeater ID="rptUserStat" runat="server" >
                                      <ItemTemplate>
                                              <div class="ul_list ul_list-icon-ok">
                                      <ul>
                                          <li><i class="icon-question-sign"></i><a href="user_questions.html">Questions<span> ( <span><%#Eval("question")==null?"0":Eval("question") %></span> ) </span></a></li>
                                          <li><i class="icon-comment"></i><a href="user_answers.html">Answers<span> ( <span><%#Eval("answer")==null?"0":Eval("answer") %></span> ) </span></a></li>
                                          <%--<li><i class="icon-star"></i><a href="user_favorite_questions.html">Favorite Questions<span> ( <span></span> ) </span></a></li>--%>
                                          <li><i class="icon-heart"></i><a href="user_points.html">Points<span> ( <span><%--<%#Eval("point")==null?"0":Eval("point") %>--%></span> ) </span></a></li>
                                          <%--<li><i class="icon-asterisk"></i>Best Answers<span> ( <span></span> ) </span></li>--%>
                                      </ul>
                                  </div>
                                      </ItemTemplate>
                                  </asp:Repeater>


What I have tried:

I have tried to Bind using DataBinder.Eval(Container.DataItem,"variable") but did not work.
Posted
Updated 11-Apr-16 23:27pm

1 solution

You should return in one select statement from SQL so that the table returned will be correctly bound. Just store those counts in temp variables and select at the last in one statement and try.
 
Share this answer
 
Comments
A94 12-Apr-16 12:24pm    
Can you please illustrate with example by modifying the above procedure or code
SELECT @Questions = COUNT(*) AS question FROM tblQuestion WHERE RegID=@RegId ;
SELECT @Answers = COUNT(*) AS answer FROM tblAnswer WHERE RegID=@RegId;

SELECT @Questions, @Answers, Points AS point FROM tblPoints WHERE RegID=@RegId;

Before using the variables declare them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900