双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

c#调用存储过程,并返回数据集

阿狸Ahri 阿狸Ahri 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "JSON";
int index =Convert.ToInt32( context.Request["pageIndex"]);
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=NetShop;Integrated Security=True");
con.Open();
string sql = string.Format("select * from NS_Shop_Discuss");
string namepro = "xp_GetPage ";
SqlParameter apa1 = new SqlParameter("@sql",SqlDbType.VarChar,255);
apa1.Value = sql;
SqlParameter apa2 = new SqlParameter("@page",SqlDbType.Int,64);
apa2.Value = index;
SqlParameter apa3 = new SqlParameter("@pageSize", SqlDbType.Int, 64);
apa3.Value = 5;
SqlParameter apa4= new SqlParameter("@totalcount", SqlDbType.Int, 64);
apa4.Direction = ParameterDirection.Output;
SqlCommand com = new SqlCommand(namepro, con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add(apa1);
com.Parameters.Add(apa2);
com.Parameters.Add(apa3);
com.Parameters.Add(apa4);
SqlDataAdapter ad=new SqlDataAdapter();
ad.SelectCommand = com;
DataSet da = new DataSet();
ad.Fill(da);
DataTable table = new DataTable();
table = da.Tables[0];
string json = CreateJsonParameters(table);

context.Response.Write(json);
}



CREATE PROCEDURE xp_GetPage
(
@sql varchar(1000),
@page int = 1,
@pageSize int = 20
@totalcount int
)
AS
SET NOCOUNT ON
DECLARE @P1 int --P1是游标的id

SET @page = (@page-1) * @pagesize + 1
EXEC sp_cursoropen @P1 output,@sql
EXEC sp_cursorfetch @P1, 16, @page, @pagesize
EXEC sp_cursorclose @P1

--上面的就够了,下面的代码是为了统计总记录条数
select @totalCount=@@RowCount


GO




为什么单步运行发现DataSet里面没值的? 可是点查看dataset里面的table[0]能查到表头,我数据库有数据的
...全文
评论 6
收藏 已收藏
分享
返回顶部
阿狸Ahri
C# 111,129 成员 642,540 内容