码迷,mamicode.com
首页 > Web开发 > 详细

asp.net如何调用存储过程

时间:2014-10-22 10:13:14      阅读:229      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!