首页 > 开发 > .Net > 正文

在.NET中调用存储过程

2020-02-03 15:56:36
字体:
来源:转载
供稿:网友
今天试了一下用存储过程取得数据。归纳方法如下:

1.用sqlcommand和dataset:
sqlconnection conn=new sqlconnection("server=(local);uid=;password=;database=");
sqlcommand cmd=new sqlcommand("storeprocedure",connn);
cmd.commandtype=commandtype.storeprocedure;

sqldataadapter dscommand=new sqldataadapter(cmd);
dataset ds=new dataset();
dscommand.fill(ds);

2.用sqlcommand和sqldataadapter
sqlconnection conn=new sqlconnection("server=(local);uid=;password=;database=");
sqlcommand cmd=new sqlcommand("storeprocedure",conn);
cmd.commandtype=commandtype.storeprocedure;
sqldatareader dr=cmd.executereader()
while(dr.read())
{
response.write(dr.item["field"]);
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表