如何将此nvarchar返回给C#

编程入门 行业动态 更新时间:2024-10-11 17:24:32
本文介绍了如何将此nvarchar返回给C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好 我有此存储过程:

hi all i have this Stored Procedure :

set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[TOP_Returner] (@number [bigint], @return_top nvarchar(200) output ) AS declare @top_name nvarchar(200) if @number=1 begin select top (1) @top_name=[product_name] From View_Product_4_TopBest set @return_top=@top_name return @return_top end if @number=2 begin select top (1) @top_name=[color_name] From View_Color_2_TopBest set @return_top=@top_name return @return_top end if @number=3 begin select top (1) @top_name=[model_name] From View_Model_2_TopBest set @return_top=@top_name return @return_top end if @number=4 begin select top (1) @top_name=[size_name] From View_Size_2_TopBest set @return_top=@top_name return @return_top end if @number=5 begin select top (1) @top_name=[group_name] from View_ProductGroup_TopBest set @return_top=@top_name return @return_top end

如何在C#应用程序中使用@return_top 请帮助我 谢谢很多

How Do I use From @return_top In C# Application Please Help Me Thank A Lot

推荐答案

SqlCommand cmd = new SqlCommand("MyStoredProcedure", cn); cmd.CommandType=CommandType.StoredProcedure; SqlParameter parm=new SqlParameter("@pkid",SqlDbType.Int); parm.Value=1; parm.Direction =ParameterDirection.Input ; cmd.Parameters.Add(parm); SqlParameter parm2=new SqlParameter("@ProductName",SqlDbType.VarChar); parm2.Size=50; parm2.Direction=ParameterDirection.Output; // This is important! cmd.Parameters.Add(parm2); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); // Print the output value Console.WriteLine(cmd.Parameters["@ProductName"].Value); Console.ReadLine();

由于@return_top是该过程的输出参数,因此应在过程内部设置它的值.您实际上并没有返回"它,只需设置值 调用过程时,定义参数,然后将参数设置为Direction至output.请参见 SqlParameter.Direction属性 [ ^ ]和ParameterDirection枚举 [ ^ ] Since the @return_top is an output parameter for the procedure, you should set it''s value inside the procedure. You don''t actually ''return'' it, only set the value When you call the procedure, you define the parameter, you set the parameter.Direction to output. See SqlParameter.Direction Property [^] and ParameterDirection Enumeration[^]

更多推荐

如何将此nvarchar返回给C#

本文发布于:2023-11-10 07:08:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574695.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:将此   nvarchar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!