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的值为存储过程中的默认值(即:'哈哈')

  • 相关阅读:
    在命令行下运行Matlab
    VMWare无法共享文件夹(Win7宿主机Ubuntu14.04客户机)
    [转] CVonline: Image Databases
    第二天
    第一天
    二宝软件的NABCD分析
    用c++实现环形数组的最大子数组之和
    返回一个二维整数数组中最大子数组的和
    求最大子数组之和
    四则运算
  • 原文地址:https://www.cnblogs.com/SALIN/p/1603854.html
Copyright © 2011-2022 走看看