• ADO.NET——获取output 和 return值


    程序代码
    //存储过程
    //Create PROCEDURE MYSQL
    //     @a int,
    //     @b int
    //AS
    //     return @a + @b
    //GO
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString());
    conn.Open();
    SqlCommand MyCommand = new SqlCommand("MYSQL", conn);
    MyCommand.CommandType = CommandType.StoredProcedure;
    MyCommand.Parameters.Add(new SqlParameter("@a", SqlDbType.Int));
    MyCommand.Parameters["@a"].Value = 10;
    MyCommand.Parameters.Add(new SqlParameter("@b", SqlDbType.Int));
    MyCommand.Parameters["@b"].Value = 20;
    MyCommand.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
    MyCommand.Parameters["@return"].Direction = ParameterDirection.ReturnValue;
    MyCommand.ExecuteNonQuery();
    Response.Write(MyCommand.Parameters["@return"].Value.ToString());
    程序代码
    //存储过程
    //Create PROCEDURE MYSQL
    //     @a int,
    //     @b int,
    //     @c int output
    //AS
    //     Set @c = @a + @b
    //GO
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString());
    conn.Open();
    SqlCommand MyCommand = new SqlCommand("MYSQL", conn);
    MyCommand.CommandType = CommandType.StoredProcedure;
    MyCommand.Parameters.Add(new SqlParameter("@a", SqlDbType.Int));
    MyCommand.Parameters["@a"].Value = 20;
    MyCommand.Parameters.Add(new SqlParameter("@b", SqlDbType.Int));
    MyCommand.Parameters["@b"].Value = 20;
    MyCommand.Parameters.Add(new SqlParameter("@c", SqlDbType.Int));
    MyCommand.Parameters["@c"].Direction = ParameterDirection.Output;
    MyCommand.ExecuteNonQuery();
    Response.Write(MyCommand.Parameters["@c"].Value.ToString());
  • 相关阅读:
    NTC3950-10K温度传感器
    Maven常用命令:
    Linux-IIC驱动(详解)
    sourceinsight4 用设置
    LTDC/DMA2D—液晶显示***
    STM32F429的LTDC和DMA2D ***
    python机器学习sklearn 岭回归(Ridge、RidgeCV)
    random_state 参数
    python3 文件及文件夹路径相关
    机器学习:简单线性回归
  • 原文地址:https://www.cnblogs.com/zeroone/p/3306553.html
Copyright © 2020-2023  润新知