Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have created a stored procedure in which there are 2 table "register" & "userquery" in db. i want to display user detail in gridview as well as total count for dashboard from this stored procedure how should i call in asp.net coz i dont know please send me a code

What I have tried:

SQL
ALTER PROCEDURE [dbo].[pDashboard]
	
	AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    DECLARE @TotalUSers INT
    DECLARE @PendingQuery INT
    DECLARE @RepliedQuery INT
    
    
    SELECT	@TotalUSers = COUNT(*)
    FROM	register
    
    
    SELECT	@PendingQuery = COUNT(*)
    FROM	USerQuery
    WHERE	QueryReply is null
    
    SELECT  @RepliedQuery = COUNT(*)
	FROM	UserQuery
	WHERE	QueryReply is not null
	
	
	SELECT	@TotalUSers as TOTALUSERS,
			@PendingQuery as PENDINGQUERY,
			@RepliedQuery as RepliedQuery
     
END
Posted
Updated 19-Mar-17 19:50pm
v2
Comments
PIEBALDconsult 19-Mar-17 16:47pm    
I doubt that a grid is the best way to present this data to the user. Particularly on a "dashboard".

1 solution

try like this

ASPX
<form id="form1" runat="server">
       <asp:GridView ID="gridView" runat="server" AutoGenerateColumns="true">
       </asp:GridView>
       <h2>Count</h2>: <asp:Label ID="lblCount" runat="server"></asp:Label>
   </form>


Stored Procedure
create procedure spGetDetails
as begin
select count(*) from SomeTable  
select Column1,Column2, ... ColumnN from SomeTable2
end

Code Behind
protected void Page_Load(object sender, EventArgs e)
       {

           if (!Page.IsPostBack)
           {
               string connectionString = "Your Connection string";
               SqlConnection con = new SqlConnection (connectionString);
               SqlCommand cmd = new SqlCommand("spGetDetails", con) {  CommandType = CommandType.StoredProcedure};
               SqlDataAdapter da = new SqlDataAdapter(cmd);
               DataSet ds = new DataSet();
               da.Fill(ds);
               DataTable dtCount = ds.Tables[0];
               DataTable dtGridData = ds.Tables[1];
               if (dtCount.Rows.Count == 1)
                   lblCount.Text = dtCount.Rows[0][0].ToString();
               gridView.DataSource = dtGridData;
               gridView.DataBind();

           }
       }
 
Share this answer
 
v2

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