VS2005中怎样使用存储过程
来源:互联网 发布:淘宝过滤流量 编辑:程序博客网 时间:2024/06/07 09:16
以下是SQL中两个存储过程:
CREATE PROCEDURE dbo.oa_selectalluser
AS
select * from UserInfo
GO
AS
select * from UserInfo
GO
CREATE PROCEDURE dbo.oa_SelectByID
@id int
AS
select * from UserInfo where ID=@id
GO
@id int
AS
select * from UserInfo where ID=@id
GO
一个是带参数的存储过程,一个是不带参数的存储过程.下面介绍怎么在VS2005中使用这两个存储过程.
(一).不带参数的存储过程:
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();
}
}
...{
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控件用来绑定执行存储过程得到的结果.
(二).带参数的存储过程:
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();
}
...{
//带参数的存储过程的使用方法
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();
}
- VS2005中怎样使用存储过程
- 怎样在SqlDataAdapter中通过Sqlcommand使用存储过程
- 怎样在C#中调用存储过程?
- 存储过程中怎样实现模糊匹配
- 怎样在存储过程中动态的使用表名,而又可以使用游标?
- 怎样捕捉存储过程执行过程中出现的错误?
- ASP中使用存储过程
- ASP中使用存储过程
- VC中使用存储过程
- VC中使用存储过程
- PHP中使用存储过程
- java中使用存储过程
- 存储过程中使用事务
- asp中使用存储过程
- JDBC中使用存储过程
- mysql 中使用存储过程
- mysql 中使用存储过程
- mysql 中使用存储过程
- JSP学习心得
- 在Linux环境下安装JSP
- 系统分析师修养
- 利用汉字在计算机里面的编码来得到汉字的首拼音:
- FileExists 方法
- VS2005中怎样使用存储过程
- 掌握 Linux 调试技术
- 《程序员》7期上市:互联网冲击企业安全
- 文人不能做事是个耻辱——走近一耽堂
- Flash读取外部文本文件
- photo in office
- Windows2000下Apache2.0.46与Tomcat5.0.2整合配置方法
- the most great Walkman phone
- 安装resin+mysql+IIS+JDK的总结