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

  • 相关阅读:
    ASFNU SC Day6
    ASFNU SC Day3
    ASFNU SC Day2
    ASFNU SC Day1
    2017-9-3 校内模拟T2取数win
    2017-9-3 校内模拟T1卡片card
    (补题)苗条的树(poj_3522)
    跳跳棋(9018_1563)(BZOJ_2144)
    Java之JSP和Servlet基础知识。
    JSP中的九大内置对象
  • 原文地址:https://www.cnblogs.com/SALIN/p/1603854.html
Copyright © 2011-2022 走看看