在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>