首页 > Web开发 > 详细

asp.net如何调用存储过程

时间:2014-10-22 10:11:14      阅读:332      评论:0      收藏:0      [点我收藏+]

在sqlserver中创建带参数的存储过程
use northwind
go
create procedure getcount
@dd datetime
as
print‘输入日期之后的有:‘
select * from Orders where OrderDate>@dd

 

在asp.net中调用存储过程
SqlConnection conn = new SqlConnection("server=.;database=northwind;user id=sa;pwd=**;");
SqlCommand comm = new SqlCommand("getcount", conn);
comm.CommandType = CommandType.StoredProcedure;
SqlParameter parm = comm.Parameters.Add("@dd",SqlDbType.DateTime);
parm.Value = "1996-8-1";
conn.Open();
SqlDataReader dr = comm.ExecuteReader();
dg.DataSource = dr;
dg.DataBind();
conn.Close();

 

在页面中加入datagrid
<form id="form1" runat="server">
<asp:DataGrid ID="dg" runat=server></asp:DataGrid>
</form>

asp.net如何调用存储过程

原文:http://net5x.blog.51cto.com/7900145/1566527

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!