sql存储过程,以及在ASP.NET中的使用

在SQL中建立的存储过程

CREATE PROCEDURE find
(@strName int)
 AS
select @strName=rtrim(@strName)
select * from khxxb
where (KHLXZ=@strName)
return
GO

在ASP.NET中的调用:
SqlConnection myconn = new SqlConnection((string)Application["Connstr"]);
   
   SqlCommand mycomm = new SqlCommand();
   SqlParameter Param=new SqlParameter("@strName",SqlDbType.Int);
   Param.Value="1";
   mycomm.Connection=myconn;
   mycomm.CommandType=CommandType.StoredProcedure;
   mycomm.CommandText="find";
   mycomm.Parameters.Add(Param);

   myconn.Open();

   DataSet ds = new DataSet();
   SqlDataAdapter da = new SqlDataAdapter(mycomm);
   da.Fill(ds);
   this.DataGrid1.DataSource = ds;
   this.DataGrid1.DataBind();

posted on 2006-07-27 09:52  张波  阅读(290)  评论(0编辑  收藏  举报