欢迎光临
我们一直在努力

SQLDataReader Vs. DataSet(好多人弄不清楚,这回大家可以看看了)-.NET教程,数据库应用

建站超值云服务器,限时71元/月
sqldatareader vs dataset
submitted by user level date of submission
arnold park intermediate 05/11/2001

  
objective:
to compare and contrast sqldatareader and sqldatasetcommand

target audience
ado.net programmer

environment
sql2000, visual studio .net beta 1
ibuyspy database

structure of table
create table [dbo].[orderdetails] (
[orderid] [int] not null ,
[productid] [int] not null ,
[quantity] [int] not null ,
[unitcost] [money] not null
) on [primary]
go

create table [dbo].[products] (
[productid] [int] identity (1, 1) not null ,
[categoryid] [int] not null ,
[modelnumber] [nvarchar] (50) collate korean_wansung_ci_as null ,
[modelname] [nvarchar] (50) collate korean_wansung_ci_as null ,
[productimage] [nvarchar] (50) collate korean_wansung_ci_as null ,
[unitcost] [money] not null ,
[description] [nvarchar] (3800) collate korean_wansung_ci_as null
) on [primary]

stored procedure
/* procedure name:net_popularproduct_selectmaster
* objective           :weekly best items top 5
*/

create procedure net_popularproduct_selectmaster
as
begin
select top 5 o.productid,sum(o.quantity) as total,p.modelname
from orderdetails o,products p
where o.productid=p.productid
group by o.productid,p.modelname
order by total desc
end

*****************source code

1)using sqldatasetcommand

conn=new common.dbconn();
sqldatasetcommand comm=new sqldatasetcommand("net_popularproduct_selectmaster",conn);
comm.selectcommand.commandtype=commandtype.storedprocedure;
dataset ds=new dataset();
comm.filldataset(ds,"popitems");
return ds;

2)using sqldatareader

conn=new common.dbconn();
sqlcommand comm=new sqlcommand("net_popularproduct_selectmaster",conn);
comm.commandtype=commandtype.storedprocedure;
conn.open();
comm.execute(out reader);
datatable table=new datatable("top5");
table.columns.add(new datacolumn("product_id",typeof(system.int32)));
table.columns.add(new datacolumn("quantity",typeof(system.int32)));
table.columns.add(new datacolumn("product_name",typeof(system.string)));

while(reader.read())
{
datarow=table.newrow();
datarow[0]=reader.getint32(0);
datarow[1]=reader.getint32(1);
datarow[2]=reader.getstring(2);
table.rows.add(datarow);
}
conn.close();
return table;

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » SQLDataReader Vs. DataSet(好多人弄不清楚,这回大家可以看看了)-.NET教程,数据库应用
分享到: 更多 (0)

相关推荐

  • 暂无文章