【发布时间】:2021-10-10 11:57:16
【问题描述】:
我正在使用 c#、asp.net、webforms 和 Visual Studio。我也在使用 SQL Server Management Studio 来创建我的存储过程。
如何按名为 RegId 的 ID 进行分组,然后显示每个 RegId 的 Title: URL 列表?
存储过程:
USE [MyDB]
GO
/****** Object: StoredProcedure [dbo].[spGetRegSess] Script Date: 8/5/2021 7:31:49 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spGetRegSess]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT *
FROM RegSess
END
我更喜欢以文本格式显示的内容:
Bob has Google at http://www.google.com, Yahoo at http://www.yahoo.com, and MSN at http://www.msn.com.
John has Reddit at http://www.reddit.com.
我的 webforms asp.net 页面上有这个按钮:
<asp:Button ID="btnSend" runat="server" OnClick="btnSend_Click" Text="Send" />
单击按钮后,我从存储过程中获取数据并将其放入数据表中:
protected void btnSend_Click(object sender, EventArgs e){
DataTable dataTable = new DataTable();
//Fill datatable
using (SqlConnection sqlConn = new
SqlConnection(ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString))
{
sqlConn.Open();
using (var command = sqlConn.CreateCommand())
{
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = "spGetRegSess";
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(dataTable);
sqlConn.Close();
da.Dispose();
var myCount = dataTable.Rows.Count;
}
sqlConn.Close();
}
}
我在这部分之后被卡住了。我知道我需要按 RegId 进行分组,但不确定执行此操作的语法。
【问题讨论】:
-
您能分享您的存储过程以及使用数据表的 Web 表单代码吗?
-
@Drewskis 当然!我已经编辑过了。