zoukankan      html  css  js  c++  java
  • 一个简单的存储过程

    CREATE PROCEDURE p_out
    @a as int,
    @b as int,
    @c as int output
    AS
    set @c=@a+@b
    return '10'
    ---------------------
    .........
    SqlCommand cmd2=new SqlCommand("p_out",conn);
    cmd2.CommandType=CommandType.StoredProcedure;
    cmd2.Parameters.Add("@a",SqlDbType.Int);
    cmd2.Parameters.Add("@b",SqlDbType.Int);
    SqlParameter para_c=cmd2.Parameters.Add("@c",SqlDbType.Int);
    SqlParameter para_r=cmd2.Parameters.Add("returnvalue",SqlDbType.Int);
    cmd2.Parameters[0].Value=2;
    cmd2.Parameters[1].Value=3;
    para_c.Direction=ParameterDirection.Output;
    para_r.Direction=ParameterDirection.ReturnValue;
    conn.open();
    cmd2.ExecuteNonQuery();
    conn.close();
    this.Response.Write(para_c.value.ToString());
    this.Response.Write(para_r.value.ToString());

    ---------------------------------------------------------------------------------------------------

    CREATE PROCEDURE sp_AccountRole_Create
    @CategoryID int,
    @RoleName nvarchar(10),
    @Description nvarchar(50),
    @RoleID int outputAS   
    DECLARE @Count int
    SELECT @Count = Count(RoleID) FROM Account_Role WHERE RoleName = @RoleName
    IF @Count = 0
    INSERT INTO Account_Role (CategoryID, RoleName, Description) values
    (@CategoryID, @RoleName, @Description) SET @RoleID = @@IDENTITY
    RETURN 1
    GO

    执行存储过程的C#过程:
    SqlConnection DbConnection = new SqlConnection(mConnectionString);
    SqlCommand command = new SqlCommand( "sp_AccountRole_Create", DbConnection );
    DbConnection.Open(connectString);
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add("@CategoryID", SqlDbType.Int, 4);
    command.Parameters.Add("@RoleName", SqlDbType.NVarChar, 10);
    command.Parameters.Add("@Description", SqlDbType.NVarChar, 50);
    command.Parameters.Add("@RoleID", SqlDbType.Int, 4);
    command.Parameters.Add("Returnvalue", SqlDbType.Int, 4, ParameterDirection.Returnvalue,false, 0,0,

    string.Empty,DataRowVersion.Default, null);
    command.parameters["@CategoryID"].value = permission.CategoryID;
    command.parameters["@RoleName"].value = permission.PermissionName;
    command.parameters["@Description"].value = permission.Description;
    command.parameters["@RoleID"].Direction = ParameterDirection.Output;
    int rowsAffected = command.ExecuteNonQuery();
    int result = command.parameters["Returnvalue"].value;
    int newID = command.parameters["@RoleID"].value;

  • 相关阅读:
    Node.js 笔记03
    Node.js 笔记02
    Node.js 笔记01
    源代码管理工具-git
    ES6笔记01
    07_查找、软链接、打包压缩、软件安装
    06_系统信息相关命令
    oracle序列中cache和nocache
    PL/SQL规范、块、过程、函数、包、触发器
    对Xcode菜单选项的详细探索(干货)
  • 原文地址:https://www.cnblogs.com/jcomet/p/1242539.html
Copyright © 2011-2022 走看看