dataTable问题
我写了一个翻页的函数,存储过程里面既有返回的数据也有返回的数据条数,但是不知道怎么写?public DataTable cspPage(string TableName,string SelectWhere,string SelectOrderId,string SelectOrder,int PageNo,int PageSize)
{
openData();
SqlCommand cmd=new SqlCommand("getdataset",conn);
cmd.CommandType=CommandType.StoredProcedure;
cmd.Parameters.Add("@TableName",SqlDbType.VarChar,50).Value=TableName;
cmd.Parameters.Add("@SelectWhere",SqlDbType.VarChar,500).Value=SelectWhere;
cmd.Parameters.Add("@SelectOrderId",SqlDbType.VarChar,100).Value=SelectOrderId;
cmd.Parameters.Add("@SelectOrder",SqlDbType.VarChar,500).Value=SelectOrder;
cmd.Parameters.Add("@intPageNo",SqlDbType.Int).Value=PageNo;
cmd.Parameters.Add("@intPageSize",SqlDbType.Int).Value=PageSize;
cmd.Parameters.Add("@RecordCount", SqlDbType.Int).Direction = ParameterDirection.Output;
SqlDataAdapter adapter=new SqlDataAdapter(cmd);
DataTable dt=new DataTable();
adapter.Fill(dt);
int count=(int)cmd.Parameters["@RecordCount"].Value;
return dt;
}
怎样把count也和数据一起返易做图去呢? --------------------编程问答-------------------- 在dt最后加一行
把count 加载这行里 --------------------编程问答-------------------- 用out +变量啊 --------------------编程问答-------------------- 例如:
private DataTable aa(out counts)
{
}
调用的时候
aa(out s) --------------------编程问答-------------------- 楼上的正解 --------------------编程问答-------------------- public DataTable cspPage(out int counts,string TableName,string SelectWhere,string SelectOrderId,string SelectOrder,int PageNo,int PageSize)
{
...
count=(int)cmd.Parameters["@RecordCount"].Value;
}
调用时:
int counts;
DataTable dt=cspPage(out counts,...); //这一步改变了counts的值
Console.WriteLine(counts); --------------------编程问答-------------------- 好像不行呢! --------------------编程问答-------------------- 再用到这个count 的地方直接调用cspPage这个方法 cspPage(。。。。。。。。).rows.count 就行了吧 --------------------编程问答-------------------- public DataTable cspPage(out int counts,string TableName,string SelectWhere,string SelectOrderId,string SelectOrder,int PageNo,int PageSize)
{
...
count=(int)cmd.Parameters["@RecordCount"].Value;
}
调用时:
int counts;
DataTable dt=cspPage(out counts,...); //这一步改变了counts的值
Console.WriteLine(counts);
看到区别了吗? --------------------编程问答-------------------- 用out参数试试!!!
补充:.NET技术 , C#