论坛
门户
内部优惠
喜欢
话题
VIP会员
搜索
新浪微博
登录
注册
100%
100%
首页
>
网页设计
>
net技术
>
在asp.net 2.0中使用存储过程
回复
« 返回列表
schack8888
风云使者
注册日期
2010-12-06
发帖数
686
QQ
火币
3641枚
粉丝
161
关注
102
加关注
写私信
打招呼
阅读:
2940
回复:
0
在asp.net 2.0中使用存储过程
楼主
#
更多
只看楼主
倒序阅读
发布于:2011-08-16 12:34
保存
100%
100%
[]
1
本文介绍了在
asp.net2.0
中使用
存储过程
的方法。
以下是SQL中两个存储过程:
[color=#990000;]以下是引用片段:
CREATE PROCEDURE dbo.oa_selectalluser
AS
select * from UserInfo
GO
CREATE PROCEDURE dbo.oa_SelectByID
@id int
AS
select * from UserInfo where ID=@id
GO
一个是带参数的存储过程,一个是不带参数的存储过程.下面介绍怎么在VS2005中使用这两个存储过程.
(一).不带参数的存储过程:
[color=#990000;]以下是引用片段:
protected void Page_Load(object sender, EventArgs e)
...{
if(!Page.IsPostBack)
...{
//不带参数的存储过程的使用方法
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["oaConnectionString"].ToString());
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds=new DataSet();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conn;
da.SelectCommand.CommandText = "oa_SelectAllUser";
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
在页面中添加了一个GridView控件用来绑定执行存储过程得到的结果.
(二).带参数的存储过程:
[color=#990000;]以下是引用片段:
protected void btn_search_Click(object sender, EventArgs e)
...{
//带参数的存储过程的使用方法
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["oaConnectionString"].ToString());
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conn;
da.SelectCommand.CommandText = "oa_SelectByID";
da.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter param = new SqlParameter("@id", SqlDbType.Int);
param.Direction = ParameterDirection.Input;
param.Value = Convert.ToInt32(txt_value.Text);
da.SelectCommand.Parameters.Add(param);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
同样,在页面中添加了一个GridView控件用来绑定执行存储过程的结果,另外,在页面中还添加了一个textbox控件和一个BUTTON按钮,上面的执行存储过程是放在按钮的onclick事件中的.textbox控件用来接收存储过程的参数.
喜欢
0
评分
0
最新喜欢:
兼职版主
回复
100%
发帖
回复
« 返回列表
普通帖
您需要登录后才可以回帖,
登录
或者
注册
100%
返回顶部
关闭
最新喜欢