c#调用存储过程,并返回数据集
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]能查到表头,我数据库有数据的
...全文
相关推荐
C#中调用oracle存储过程返回数据集
C#中调用oracle存储过程返回数据集
C#中调用ORACLE的PACKAGE里方法和存储过程的应用
1、首先在ORACLE里建立如下PACKAGE PACKAGE分SPEC和body两部分 2、C#部分代码
C#中调用MySQL存储过程的方法
主要介绍了C#中调用MySQL存储过程的方法,涉及C#数据库操作的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
c#调用存储过程例子
c#调用存储过程例子c#调用存储过程例子c#调用存储过程例子c#调用存储过程例子c#调用存储过程例子c#调用存储过程例子c#调用存储过程例子c#调用存储过程例子c#调用存储过程例子c#调用存储过程例子
C#调用存储过程简单完整例子
C#调用存储过程简单完整例子C#调用存储过程简单完整例子



