学习

chouer

  博客中心 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 登录 ::
  2 随笔 :: 948 文章 :: 8 评论 :: 0 Trackbacks
Cached @ 2025/4/28 15:28:46Control ASP.skins_cogitation_controls_blogstats_ascx
<2025年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

News

留言簿(0)

随笔档案

文章分类

文章档案

搜索

最新评论

  • 1. SAP资料下载
  • SAP下载网,
    SAP资料共享网站,完全免费
    资料全由网友共享,大家共享,大家下载
  • --SAP99

阅读排行榜

评论排行榜

Cached @ 2025/4/28 15:28:46Control ASP.skins_cogitation_controls_singlecolumn_ascx

使用輸出參數,可以使儲存過程返回多個值.例如,查詢某表的信息,並希望返回表的記錄數,可以在儲存過程中使用輸出參數.

create procedure employeesproc

@empCount int output

as

select * from employees

select  @empCount=count(*) from employees

go

@empCount參數後面,加了output關鍵字,表示這是一個輸出參數.outputSQL Server數據庫定義的關鍵字.

SqlParameter對象的Direction屬性,這個屬性用來指定參數的類型.Direction屬性是ParameterDirection枚舉類型.

Input 指定參數是輸入參數

InputOutput 指定參數既能輸入,也能輸出

OutPut 指定參數是輸出參數

Return Value 指定參數表示如儲存過程,內置函數或用戶定義函數之類的操作返回值

其中Direction屬性的默認值是Input

myCommand.Parameters.add(“@empCount”,SqlDbType.Int);

myCommand.Parameter[“@empCount”].Direction=ParameterDirection.Output;

//創建數據儲存過程

create procedure elogin1_ws

@bumen nvarchar(25),

@empcount int output

as

--查詢滿足條件的記錄

select 部門名稱,工號,中文姓名,nt from elogin1

where 部門名稱=@bumen

--統計滿足條件的記錄數

select @empcount=count (*) from elogin1 where  部門名稱=@bumen

GO

//乘隙中調用儲存過程

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)

          {

               //創建數據庫連接字符串

               string connstr="server=10.64.2.80;user id=ieb;pwd=ieb;database=cust";

//創建Connection and Command對象

               SqlConnection myconn=new SqlConnection(connstr);

               SqlCommand mycommand=new SqlCommand("elogin1_ws",myconn);

//指定要執行的命令為儲存過程

                mycommand.CommandType=CommandType.StoredProcedure;

//增加輸入參數,並賦值

               mycommand.Parameters.Add("@bumen",SqlDbType.NVarChar,25);

               mycommand.Parameters["@bumen"].Value =this.DropDownList1.SelectedItem.Text;

               mycommand.Parameters["@bumen"].Direction=ParameterDirection.Input;

//增加輸出參數

               mycommand.Parameters.Add("@empcount",SqlDbType.Int);

               mycommand.Parameters["@empcount"].Direction=ParameterDirection.Output;

               //創建DataAdapter對象填充數據

               DataSet ds=new DataSet();

               SqlDataAdapter da=new SqlDataAdapter(mycommand);

               da.Fill(ds,"elogin1");

               //使用Label控件顯示輸出參數的輸出值

               this.Label1.Text=mycommand.Parameters["@empcount"].Value.ToString();

//將返回的數據和DataGrid綁定顯示

               this.DataGrid1.DataSource=ds.Tables["elogin1"];

               this.DataGrid1.DataBind();

          }

分享按钮发布于: 2006-09-22 12:33 chouer 阅读(545) 评论(0)  编辑 收藏

评论

标题
姓名
主页
内容 
  登录  使用高级评论  Top 订阅回复  取消订阅
[使用Ctrl+Enter键可以直接提交]