zoukankan      html  css  js  c++  java
  • C#获取存储过程的Return返回值和Output输出参数值

    1.获取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()); 

    2.获取Output输出参数值 


    程序代码 
    //存储过程 
    //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());
  • 相关阅读:
    ASPxGridView控件的基本属性
    未整理笔记
    ASPxGridView中Command列自定义按钮点击事件概要
    Cookie的使用
    ASPxGridView行的选中和行的焦点
    改变“骨感”,让OKR变得“丰满”
    高成就者的5个共同点
    项目的风险管理
    实际执行动作对OKR目标落地的重要性
    13种公认的高绩效习惯
  • 原文地址:https://www.cnblogs.com/heimirror/p/1212765.html
Copyright © 2011-2022 走看看