Username: Password:

SQLDataReader Vs. DataSet(好多人弄不清楚,这回大家能够看看了)-.NET教程,数据库应用
来源:作者: 发布时间:2007-12-26 02:13:47

sqldatareader vs dataset
submitted byuser leveldate of submission
arnold parkintermediate05/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;

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅