在C#中调用存储过程中的两种返回值
来源:互联网 发布:淘宝店招改全屏代码 编辑:程序博客网 时间:2024/06/08 17:39
//存储过程
//create proc authors_count @outrus int output
//as
//declare @authors int
//select @authors=count(*) from authors
//set @outrus=@authors
//return @authors
System.Data.SqlClient.SqlConnection sqlcon=new System.Data.SqlClient.SqlConnection("server=(local);database=pubs;uid=sa;pwd=;");
System.Data.SqlClient.SqlCommand sqlcmd=new System.Data.SqlClient.SqlCommand("authors_count",sqlcon);
sqlcmd.CommandType=System.Data.CommandType.StoredProcedure;
// sqlcmd.CommandText="authors_count";
// sqlcmd.Connection=sqlcon;
sqlcmd.Parameters.Add("@rus",System.Data.SqlDbType.Int);
sqlcmd.Parameters.Add("@outrus",System.Data.SqlDbType.Int);
sqlcmd.Parameters[0].Direction=System.Data.ParameterDirection.ReturnValue;
sqlcmd.Parameters[1].Direction=System.Data.ParameterDirection.Output;
sqlcon.Open();
//int res=(int)sqlcmd.ExecuteNonQuery();//此时返回的不是存储过程的返回值,以上只是返回delete,update,insert所影响的行数
sqlcmd.ExecuteNonQuery();
string res=sqlcmd.Parameters[0].Value.ToString();//这样就可以得到存储过程的返回值
sqlcon.Close();
this.label1.Text="存储过程的返回值是:"+res.ToString();//由return 返回
this.label2.Text="存储过程中返回的output值:"+sqlcmd.Parameters[1].Value.ToString();//由output返回
//create proc authors_count @outrus int output
//as
//declare @authors int
//select @authors=count(*) from authors
//set @outrus=@authors
//return @authors
System.Data.SqlClient.SqlConnection sqlcon=new System.Data.SqlClient.SqlConnection("server=(local);database=pubs;uid=sa;pwd=;");
System.Data.SqlClient.SqlCommand sqlcmd=new System.Data.SqlClient.SqlCommand("authors_count",sqlcon);
sqlcmd.CommandType=System.Data.CommandType.StoredProcedure;
// sqlcmd.CommandText="authors_count";
// sqlcmd.Connection=sqlcon;
sqlcmd.Parameters.Add("@rus",System.Data.SqlDbType.Int);
sqlcmd.Parameters.Add("@outrus",System.Data.SqlDbType.Int);
sqlcmd.Parameters[0].Direction=System.Data.ParameterDirection.ReturnValue;
sqlcmd.Parameters[1].Direction=System.Data.ParameterDirection.Output;
sqlcon.Open();
//int res=(int)sqlcmd.ExecuteNonQuery();//此时返回的不是存储过程的返回值,以上只是返回delete,update,insert所影响的行数
sqlcmd.ExecuteNonQuery();
string res=sqlcmd.Parameters[0].Value.ToString();//这样就可以得到存储过程的返回值
sqlcon.Close();
this.label1.Text="存储过程的返回值是:"+res.ToString();//由return 返回
this.label2.Text="存储过程中返回的output值:"+sqlcmd.Parameters[1].Value.ToString();//由output返回
- 在C#中调用存储过程中的两种返回值
- 在C#如何调用存储过程中返回多个值
- 在C#中使用sqlClient和Odbc两种连接方法调用存储过程简述
- C#中调用存储过程并且具有返回值
- c#调用存储过程两种方法
- c#调用存储过程两种方法
- C#调用存储过程返回值
- C#调用存储过程返回值
- C#调用存储过程返回值
- C#调用存储过程返回值
- C# 调用存储过程Return返回值
- 怎样在C#中调用存储过程?
- 在C#中调用存储过程
- 如何在C#中调用存储过程
- MSSQL2000中存储过程返回值及TOP在存储过程中的用法
- SQLServer 中存储过程返回的三种方式( 包括存储过程的创建, 在存储过程中调用, 在VS中调用的方法)
- C#调用存储过程返回值 (登录代码)
- C# 2.0 Vista,sql2000带返回值存储过程调用
- 到底还是建立了这项
- IE功能菜单
- cisco交换机trunk与switchport access vlan vlan-id共存的问题
- Hibernate常见的20个问题
- 黑手党历史
- 在C#中调用存储过程中的两种返回值
- 嵌入式Linux应用程序开发详解
- 外交部:中华台北奥组委认可火炬传递线路
- 八个笑话八个哲理
- ORACLE体系结构之集群(RAC)
- FLEX2对SVG的支持
- ORACLE实例与数据库的区别
- XP下的网络和P2P编程SDK
- C#的6种常用集合类大比拼