| 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()) |
