使用C# 写一个处理有返回多个记录集的存储过程存储过程如下:CREATE PROC adminLogin
@intID int
AS
set nocount on
BEGIN
select title,hits from workList where id=@intID select id,title,hits from workList
END
GO///////////////////////////然后希望在页面中显示第一个记录集格式如下 title---hits 如 测试标题---1000
第二个记录集格式如下 id---titile---hits 如 10---测试标题---1000
希望各位能给我一个完整的实例,也就是把你代码复制过来不用加一字就能运行的那种因为我是初学者,希望各位能帮帮忙,让你多打一些无关紧要的字符了数据库名 testAspx 账号 sa 密码 sa 本机ip 表名 myTest
@intID int
AS
set nocount on
BEGIN
select title,hits from workList where id=@intID select id,title,hits from workList
END
GO///////////////////////////然后希望在页面中显示第一个记录集格式如下 title---hits 如 测试标题---1000
第二个记录集格式如下 id---titile---hits 如 10---测试标题---1000
希望各位能给我一个完整的实例,也就是把你代码复制过来不用加一字就能运行的那种因为我是初学者,希望各位能帮帮忙,让你多打一些无关紧要的字符了数据库名 testAspx 账号 sa 密码 sa 本机ip 表名 myTest
--试试
CREATE PROC adminLogin
@intID int
AS
set nocount on
BEGIN
select id,title,hits from workList
union all
select 0 as id,title,hits from workList where id=@intID
END
GO
--测试语句如下
use pubs
select top 2 emp_id,fname,hire_date from employee
union all
select '0' as emp_id,fname,hire_date from employee where emp_id='h-b39728f'
结果:
PMA42628M Paolo 1992-08-27 00:00:00.000
PSA89086M Pedro 1990-12-24 00:00:00.000
0 Helen 1989-09-21 00:00:00.000
一个回复,一个从不懂到入门的.net程序员诞生了
新手就更应该学习自己动手,
只能告诉你最好不要在一个存储过程中返回两个记录集,用C#中的DataTable或DataView实现:
首先返回select id,title,hits from workList 填充到一个datatable里面;
然后select 0 as id,title,hits from workList where id=@intID 中从datatable内部筛选(ds.select("id=1"))
SqlParameter[] parm = null;
if (conn != null)
{
try
{
string sql = "StoredProcedureName";//存储过程的名字 parm = new SqlParameter[] {
new SqlParameter("@orgId",SqlDbType.Int)//增加参数
};
SqlCommand cmd=new SqlCommand(sql,conn);
cmd.Connection.Open();
parm[0].Value = deviceUserGroupId;//
cmd.CommandType=CommandType.StoredProcedure;//指定cmd的执行类型是存储过程
cmd.Parameter.AddRange(parm);
SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read())
{
//select title,hits from workList where id=@intID 的记录
}
read.NextResult();//下一条记录
while (reader.Read())
{
//select id,title,hits from workList 的记录
} reader.Close();
}
catch (Exception ex)
{
Debug.WriterLine(ex.Message);
}
finally
{
try
{
conn.Close();
}
catch { }
}
}
打的手好累。可能有错误,因为是手打的.大概意思就是这样,自己体会下。
CREATE PROC adminLogin
@intID int
AS
set nocount on
BEGIN
select title,hits from workList where id=@intID select id,title,hits from workList
END
GO
入门这个是很难的,我现在就是入不了门,可能你的一个实例回复,我就入门了啊
while (reader.Read())
{
//select title,hits from workList where id=@intID 的记录
}
read.NextResult();//下一条记录
while (reader.Read())
{
//select id,title,hits from workList 的记录
} 这里面要怎么处理
List<string> list=new List<string>();
while (reader.Read())
{
//select title,hits from workList where id=@intID 的记录
已经取得记录了 你可以增加到数组中去阿
比如 list.Add((int)reader[0]); 取得 title的记录。
也可以按照名字取得list.Add((int)reader["title"]); //记得要转换一下 int就转换int,string等.等。
}
read.NextResult();//下一条记录集
while (reader.Read())
{
//select id,title,hits from workList 的记录
}
英文的
希望你能看懂。
中文的太垃圾了。全市抄的