• c# 调用SQL Server存储过程返回值(转)


    --用ParameterDirection.ReturnValue; 返回值
    CREATE PROCEDURE dbo.a
    AS
    declare @i int
    select   @i=count(*) from tbD_M_Modle
    return @i
    GO

    --用ParameterDirection.Output; 参数返回值
    CREATE PROCEDURE dbo.a
    @i int output
    AS

    select   @i=count(*) from tbD_M_Modle
    return @i
    GO


    //
    SqlCommand cmd = new SqlCommand("a", myConn);
    cmd.CommandType = CommandType.StoredProcedure;

    //输入值
    //SqlParameter a1 = new SqlParameter("@a", SqlDbType.VarChar, 100);
    //a1.Value="aaa";
    //cmd.Parameters.Add(a1);

    //返回值
    SqlParameter i = new SqlParameter("@ii", SqlDbType.Int,4);
    i.Direction = ParameterDirection.Output;
    //i.Direction = ParameterDirection.ReturnValue;

    cmd.Parameters.Add(i);

    cmd.ExecuteNonQuery();

    string strReturn = i.Value.ToString(); //返回值--方法1
    string a = cmd.Parameters["@ii"].Value.ToString(); ////返回值--方法2

    cmd.Connection.Close();

  • 相关阅读:
    Kth Smallest Element in a BST
    Bitwise AND of Numbers Range
    Happy Number
    Summary Ranges
    linux设置MySQL开机自动启动
    基本PSO算法实现(Java)
    Invert Binary Tree
    Rectangle Area
    Contains Duplicate II
    Contains Duplicate
  • 原文地址:https://www.cnblogs.com/huhu456/p/2347179.html
Copyright © 2020-2023  润新知