在gridview中显示用户详细信息以及存储过程的总计数 [英] Display user detail in gridview as well as total count from store procedure
本文介绍了在gridview中显示用户详细信息以及存储过程的总计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个存储过程,其中有2个表register& db中的userquery。我想在gridview中显示用户详细信息以及从这个存储过程中显示仪表板的总数我应该如何在asp.net中调用coz我不知道请给我发一个代码
我尝试过:
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:
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
推荐答案
试试这样
ASPX
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();
}
}
这篇关于在gridview中显示用户详细信息以及存储过程的总计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文