zoukankan      html  css  js  c++  java
  • 存储过程的参数默认值的问题

    存储过程的参数默认值如果有填的话,在.net里面不写这个参数的SqlParameter,直接使用的是他在存储过程的默认值存储,但是如果该参数没有默认值的话,在.net代码里面一定要写对应的SqlParameter,否则会出错。

    如存储过程sp_insert_info

    ALTER PROCEDURE dbo.sp_insert_info
    @info_id int output,
    @info_citycode nvarchar(50),
    @info_areacode nvarchar(50),
    @info_gqlxid int,
    @info_gqlbid int,
    @info_price nvarchar(50)='哈哈',
    @info_title nvarchar(50),
    @info_content nvarchar(1000),

    cs代码写里面

                SqlParameter[] parameters = {
         new SqlParameter("@info_id", SqlDbType.Int,4),
         new SqlParameter("@info_citycode", SqlDbType.NVarChar,50),
         new SqlParameter("@info_areacode", SqlDbType.NVarChar,50),
         new SqlParameter("@info_gqlxid", SqlDbType.Int,4),
         new SqlParameter("@info_gqlbid", SqlDbType.Int,4),
         new SqlParameter("@info_title", SqlDbType.NVarChar,50),
         new SqlParameter("@info_content", SqlDbType.NVarChar,1000)};

                parameters[0].Direction = ParameterDirection.Output;
                parameters[1].Value = model.info_citycode;
                parameters[2].Value = model.info_areacode;
                parameters[3].Value = model.info_gqlxid;
                parameters[4].Value = model.info_gqlbid;
                parameters[5].Value = model.info_title;
                parameters[6].Value = model.info_content;

    完成可以执行,参数info_price的值为存储过程中的默认值(即:'哈哈')

  • 相关阅读:
    三、FileStream 文件流基本操作
    NetCore3.1+Flurl..Http_FluentHttp 增删改查
    CryptoJS与C#AES加解密互转
    C#生成随机字符串
    IIS发布网站之后,页面图片和js未加载出错
    web中浏览PDF文件
    ASP.NET下使用Combres对JS、CSS合并和压缩
    jQuery截取字符串、日期字符串转Date、获取html中的纯文本
    jquery格式化时间
    jQuery限制文本框的输入长度
  • 原文地址:https://www.cnblogs.com/SALIN/p/1603854.html
Copyright © 2011-2022 走看看