Csharp: Calling Output Parameters and Return Values in ADO.NET

简介: --sql code Geovin Du IF EXISTS (SELECT * FROM sysobjects WHERE [name] = 'proc_Select_AssessmentProjectSetSearch') DROP PROCEDURE proc_Select_AssessmentProjectSetSearch GO CREATE PROCEDURE proc
--sql code Geovin Du
IF EXISTS (SELECT * FROM sysobjects WHERE [name] = 'proc_Select_AssessmentProjectSetSearch')
DROP PROCEDURE proc_Select_AssessmentProjectSetSearch
GO
CREATE PROCEDURE proc_Select_AssessmentProjectSetSearch
(
	@AssessmentProjectSetJobType Uniqueidentifier,		--考核職位類型
	@AssessmentProjectSetUidKey nvarchar(2000) output	--考核項目
)
AS
declare @sql nvarchar(4000),@where nvarchar(4000)--,@AssessmentProjectSetUidKey nvarchar(4000)
set @where=''
select @AssessmentProjectSetUidKey=cast(AssessmentProjectSetUidKey as nvarchar(4000)) from AssessmentProjectSet where AssessmentProjectSetJobType=@AssessmentProjectSetJobType
set @sql='SELECT * FROM AssessmentProjectList where AssessmentProjectID in('
if(@AssessmentProjectSetUidKey IS null or @AssessmentProjectSetUidKey='')
begin
set @AssessmentProjectSetUidKey='1'
SET @where=@AssessmentProjectSetUidKey
end
else
begin
set @where=@AssessmentProjectSetUidKey
end
--print @AssessmentProjectSetUidKey
set @sql=@sql+@where+')'
--print @sql
exec (@sql)
GO

--測試
declare @s nvarchar(2220)
exec proc_Select_AssessmentProjectSetSearch '7606598a-34da-43e3-a107-950ae724b80d',@s output
select @s

---
IF EXISTS (SELECT * FROM sysobjects WHERE [name] = 'proc_Select_AssessmentProjectSetReturnSearch')
DROP PROCEDURE proc_Select_AssessmentProjectSetReturnSearch
GO
CREATE PROCEDURE proc_Select_AssessmentProjectSetReturnSearch
(
	@AssessmentProjectSetJobType Uniqueidentifier,		--考核職位類型
	@AssessmentProjectSetUidKey nvarchar(2000) output	--考核項目
)
AS
declare @sql nvarchar(4000),@where nvarchar(4000),@return int --,@AssessmentProjectSetUidKey nvarchar(4000)
set @where=''
select @AssessmentProjectSetUidKey=cast(AssessmentProjectSetUidKey as nvarchar(4000)) from AssessmentProjectSet where AssessmentProjectSetJobType=@AssessmentProjectSetJobType
set @sql='SELECT * FROM AssessmentProjectList where AssessmentProjectID in('+@AssessmentProjectSetUidKey+')'

exec (@sql)
if(@@error>0)
   set @return=2
else
 set @return=1
return @return
--return @AssessmentProjectSetUidKey  --C# 中操作不可以字符類型 SQL上可以查詢

GO

--測試
declare @s nvarchar(2220)
exec proc_Select_AssessmentProjectSetReturnSearch '330FEE4C-A17E-46A4-9460-CA4DEB782ADF',@s output
select @s

sharp code

  /// <summary>
        /// 塗聚文 20130119
        /// 返回輸出參數
        /// </summary>
        /// <param name="assessmentProjectSetJobType"></param>
        /// <param name="Return">輸出參數</param>
        /// <returns></returns>
        public DataTable SelectAssessmentProjectSetJobTypeDataTableSearch(Guid assessmentProjectSetJobType,out string Return)
        {
            DataTable dt = new DataTable();
            try
            {
               // SqlParameter par = new SqlParameter("@AssessmentProjectSetJobType ", assessmentProjectSetJobType);
                SqlParameter[] par = new SqlParameter[]{
				//new SqlParameter("@AssessmentProjectSetID",SqlDbType.Int,4),
				new SqlParameter("@AssessmentProjectSetJobType",SqlDbType.UniqueIdentifier),
				new SqlParameter("@AssessmentProjectSetUidKey",SqlDbType.NVarChar,4000),
                //new SqlParameter("@return",SqlDbType.Int,8),
				};
                par[0].Value = assessmentProjectSetJobType;
                par[1].Direction = ParameterDirection.Output;

                using (DataTable reader = DBHelper.GetTable("proc_Select_AssessmentProjectSetSearch", CommandType.StoredProcedure, par))
                {
                    dt = reader;
                    Return =(string)par[1].Value.ToString();
                }
            }
            catch (SqlException ex)
            {

                throw ex;
            }
            return dt;
        }
        /// <summary>
        /// 塗聚文 20130119
        /// 返回自定義參數
        /// </summary>
        /// <param name="assessmentProjectSetJobType"></param>
        /// <param name="Return">自定義參數</param>
        /// <returns></returns>
        public DataTable SelectAssessmentProjectSetReturnDataTableSearch(Guid assessmentProjectSetJobType, out string Return)
        {
            DataTable dt = new DataTable();
            try
            {
                // SqlParameter par = new SqlParameter("@AssessmentProjectSetJobType ", assessmentProjectSetJobType);
                SqlParameter[] par = new SqlParameter[]{
				//new SqlParameter("@AssessmentProjectSetID",SqlDbType.Int,4),
				new SqlParameter("@AssessmentProjectSetJobType",SqlDbType.UniqueIdentifier),
				new SqlParameter("@AssessmentProjectSetUidKey",SqlDbType.NVarChar,4000),
                new SqlParameter("@return",SqlDbType.Int,8),
				};
                par[0].Value = assessmentProjectSetJobType;
                par[1].Direction = ParameterDirection.Output; 
                par[2].Direction = ParameterDirection.ReturnValue;//ReturnValue返回值數值類型
                using (DataTable reader = DBHelper.GetTable("proc_Select_AssessmentProjectSetReturnSearch", CommandType.StoredProcedure, par))
                {
                    dt = reader;
                    Return = (string)par[1].Value.ToString();
                    int f = (int)par[2].Value;
                }
            }
            catch (SqlException ex)
            {

                throw ex;
            }
            return dt;
        }



 

目录
相关文章
|
4月前
DevTools failed to load source map: Could not load content for…System error: net::ERR_FILE_NOT_FOUN
DevTools failed to load source map: Could not load content for…System error: net::ERR_FILE_NOT_FOUN
|
数据库
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
602 0
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
TestRange.cs error CS0104: `Range' is an ambiguous reference between `System.Range' and Gtk.Range
TestRange.cs error CS0104: `Range' is an ambiguous reference between `System.Range' and Gtk.Range
135 0
1. (arg0: bool) -> mediapipe.python._framework_bindings.packet.Packet
1. (arg0: bool) -> mediapipe.python._framework_bindings.packet.Packet
913 0
How to add extension field to report
How to add extension field to report
106 0
|
算法
On the Correct and Complete Enumeration of the Core Search Space
在之前的文章中我们讨论了基于graph的DP-based算法,来解决join ordering的枚举问题。 这些DP算法通过join predicate描述的连通性,解决了枚举可能的表组合问题,但join graph本身(即使hypergraph)是无法完整的描述join语义的,因为连通边本身无法描述不同类型的join语义,例如left outer join/semi join/anti join...,因此即使找到了所谓的csg-cmp-pair,也不一定是有效的plan。 这篇paper讨论的就是这个问题,当枚举出一个csg-cmp-pair (S1 o S2),如何判断这是有效的join
373 0
On the Correct and Complete Enumeration of the Core Search Space