zoukankan      html  css  js  c++  java
  • C#存储过程Output返回参数 方法调用类

    存储过程:

    create proc proc_GetUserID 
    @UserName nvarchar(50),@ID int output 
    as
    begin
        
    set @ID = (select ID from UserAccount where UserName = @UserName)
    end

    C#代码:

            private void GetUserID(string userName)
            {
                SqlParameter[] paras 
    = new SqlParameter[2];
                paras[
    0= new SqlParameter("@UserName", userName);
                paras[
    1= new SqlParameter("@ID",SqlDbType.Int);
                paras[
    1].Direction = ParameterDirection.Output;
                
    object o = DataAccess.ExcuteNonQuery_Proc_Output("proc_GetUserID", paras, "@ID");
                
    if (o == null || o.ToString() == "")
                {
                    
    this.Label1.Text = "没有这个用户名";
                }
                
    else
                {
                    
    this.Label1.Text = o.ToString();
                }
            }
    public class DataAccess
    {
            
    public static object ExcuteNonQuery_Proc_Output(string procName, SqlParameter[] parameters,string outName)
            {
                SqlConnection conn 
    = GetConnection();
                SqlCommand cmd 
    = new SqlCommand();
                cmd.Connection 
    = conn;
                cmd.CommandType 
    = CommandType.StoredProcedure;
                cmd.CommandText 
    = procName;
                
    for (int i = 0; i < parameters.Length; i++)
                {
                    cmd.Parameters.Add(parameters[i]);
                }
                conn.Open();
                
    int n = cmd.ExecuteNonQuery();
                
    object o = cmd.Parameters[outName].Value;
                conn.Close();
                
    return o;
            }
    }
  • 相关阅读:
    Webpack2 那些路径
    Nginx alias 和 root配置
    前端代码监控
    Class和构造函数的异同
    Async和await
    如何在git中删除指定的文件和目录
    微信小程序数字转化条形码和二维码
    vue 结合swiper插件实现广告公告上下滚动的效果
    vue2.0 结合better-scroll 实现下拉加载
    FormData对象提交表单和form提交表单
  • 原文地址:https://www.cnblogs.com/taizhouxiaoba/p/1446710.html
Copyright © 2011-2022 走看看