国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

SQLDataReader Vs. DataSet(好多人弄不清楚,這回大家可以看看了)

2024-07-21 02:23:50
字體:
來源:轉載
供稿:網友
sqldatareader vs datasetsubmitted byuser leveldate of submissionarnold 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 sqldatasetcommandconn=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 sqldatareaderconn=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;
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泰兴市| 樟树市| 维西| 泾阳县| 临猗县| 剑河县| 安义县| 宣汉县| 阿坝| 邓州市| 通许县| 西昌市| 奎屯市| 太仆寺旗| 兰考县| 墨江| 濮阳市| 南丹县| 潞城市| 嫩江县| 忻州市| 喀喇| 武安市| 玉门市| 浙江省| 黑龙江省| 宝山区| 吉安县| 阿城市| 南澳县| 邛崃市| 滨州市| 唐河县| 高密市| 吉林市| 兴国县| 永川市| 永顺县| 泽库县| 盘山县| 永德县|