1. System.Data

The ParameterDirection values are used by the parameter direction properties of OleDbParameter and SqlParameter.

2.  ParameterDirection是一个枚举类型,提供了四种参数类型:

using System;

namespace System.Data
{
    // Summary:
    //     Specifies the type of a parameter within a query relative to the System.Data.DataSet.
    public enum ParameterDirection
    {
        // Summary:
        //     The parameter is an input parameter.
        Input = 1,
        //
        // Summary:
        //     The parameter is an output parameter.
        Output = 2,
        //
        // Summary:
        //     The parameter is capable of both input and output.
        InputOutput = 3,
        //
        // Summary:
        //     The parameter represents a return value from an operation such as a stored
        //     procedure, built-in function, or user-defined function.
        ReturnValue = 6,
    }
}

==

    // 摘要:
    // 指定查询内的有关 System.Data.DataSet 的参数的类型。
    public enum ParameterDirection
    {
        // 摘要:
        //     参数是输入参数。
        Input = 1,
        //
        // 摘要:
        //     参数是输出参数。
        Output = 2,
        //
        // 摘要:
        //     参数既能输入,也能输出。
        InputOutput = 3,
        //
        // 摘要:
        //     参数表示诸如存储过程、内置函数或用户定义函数之类的操作的返回值。
        ReturnValue = 6,
    }

3.简单说明:

1). .Net中的参数定义为形式参数 而把存储过程的参数定义为实际参数;

2). 数据库存储过程的实际参数如果没有默认值则形式参数必须传值给实际参数;

3). 但是如果形式参数的类型为ParameterDirection.Output 则传给实际参数的永远是空值;

4). 如果形式参数的类型为ParameterDirection.ReturnValue 则形式参数不会传值给实际参数 实际参数必须有默认值  否则代码会报错;

5). 如果形式参数类型为ParameterDirection.InputOutput 或者 ParameterDirection.Output 则实际参数必须有output 关键字.

4.Example 实例 :

static void GetSalesByCategory(string connectionString,  string categoryName)
{
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        // Create the command and set its properties.
        SqlCommand command = new SqlCommand();
        command.Connection = connection;
        command.CommandText = "SalesByCategory";
        command.CommandType = CommandType.StoredProcedure;

// Add the input parameter and set its properties.
        SqlParameter parameter = new SqlParameter();
        parameter.ParameterName = "@CategoryName";
        parameter.SqlDbType = SqlDbType.VarChar;
        parameter.Direction = ParameterDirection.Input;
        parameter.Value = categoryName;

// Add the parameter to the Parameters collection. 
        command.Parameters.Add(parameter);

// Open the connection and execute the reader.
        connection.Open();
        SqlDataReader reader = command.ExecuteReader();

if (reader.HasRows)
        {
            while (reader.Read())
            {
                Console.WriteLine("{0}: {1:C}", reader[0], reader[1]);
            }
        }
        else
        {
            Console.WriteLine("No rows found.");
        }
        reader.Close();
    }
}

另外需要注意的是在.net中 System.DBNull.Value表示数据库参数为空值 而不是null.

        private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)
        {
            if (command == null) throw new ArgumentNullException("command");
            if (commandParameters != null)
            {
                foreach (SqlParameter p in commandParameters)
                {
                    if (p != null)
                    {
                        // Check for derived output value with no value assigned
                        if ((p.Direction == ParameterDirection.InputOutput ||
                            p.Direction == ParameterDirection.Input) &&
                            (p.Value == null))
                        {
                            p.Value = DBNull.Value;
                        }
                        command.Parameters.Add(p);
                    }
                }
            }
        }

ParameterDirection参数类型相关推荐

  1. System.Data : ParameterDirection参数类型

    1. System.Data The ParameterDirection values are used by the parameter direction properties of OleDb ...

  2. c# 调用oracle存储过程(参数类型不对)排坑之BindByName参数

    介绍:Oracle.ManagedDataAccess.dll c# ado调用oracle存储过程报错(参数类型不对.顺序不对等等问题),只需要加上BindByName=true即可,使用微软自带的 ...

  3. Python 函数参数有冒号 声明后有- 箭头 返回值注释 参数类型注释

    在python3.7 环境下 函数声明时能在参数后加冒号,如图: 1 def f(ham: str, eggs: str = 'eggs') -> str : 2 print("Ann ...

  4. python参数类型限定_python限定方法参数类型、返回值类型、变量类型等|python3教程|python入门|python教程...

    https://www.xin3721.com/eschool/python.html typing模块的作用 自python3.5开始,PEP484为python引入了类型注解(type hints ...

  5. 《C++面向对象高效编程(第2版)》——3.11 类名、成员函数名、参数类型和文档...

    本节书摘来自异步社区出版社<C++面向对象高效编程(第2版)>一书中的第3章,第3.11节,作者: [美]Kayshav Dattatri,更多章节内容可以访问云栖社区"异步社区 ...

  6. 秒懂JVM的三大参数类型,就靠这十个小实验了

    来源 | 悟空聊架构(ID:PassJava666) 本实验的目的是讲解 JVM 的三大参数类型.在JVM调优中用到的最多的 XX 参数,而如何去查看和设置 JVM 的 XX 参数也是调优的基本功,本 ...

  7. c语言函数参数类型检查,内联函数在编译时是否做参数类型检查?

    先说宏和函数的区别: 1. 宏做的是简单的字符串替换(注意是字符串的替换,不是其他类型参数的替换),而函数的参数的传递,参数是有数据类型的,可以是各种各样的类型. 2. 宏的参数替换是不经计算而直接处 ...

  8. 判断exception类型_C++核心准则T.44:使用函数模板推断类模板参数类型(如果可能)...

    T.44: Use function templates to deduce class template argument types (where feasible) T.44:使用函数模板推断类 ...

  9. 关于mybatis的参数2个使用经验(类似于struts2的通配所有页面的action配置,xmlsq语句参数类型为基本类型时的快捷指定办法)...

    1.我们都知道在struts2中为防止浏览器绕过struts过滤器直接请求页面,所以我们都会配置一个拦截所有页面的action,如下: <action name="*"> ...

最新文章

  1. Android ProgressBar 加载中界面实现(loading 动画) 实现菊花的效果
  2. 自学Springboot(一)
  3. centos 6.2 vnc
  4. 有哪些适合大学生浏览的网站?
  5. HDC.Cloud | 基于IoT Studio自助生成10万行代码的奥秘
  6. nccloud开发环境搭建_VS Code 搭建开发环境
  7. 透过WebGL 3D看动画Easing函数本质
  8. 解决sendmail服务启动慢的方法
  9. jquey 批量操作 checkbox
  10. 快速搭建ELK7.5版本的日志分析系统--搭建篇
  11. 英语听说计算机考试演练专用,新中高考英语听说机考时间确定,月底中考模考演练...
  12. 了解计算机网络拓扑结构,认识计算机网络拓扑结构
  13. Matlab命令系列之目录操作
  14. android WebView加载不出网页里的视频内容出现This request has been blocked; the content must be served over HTTPS.
  15. 内存分配-堆-栈-静态区
  16. 数据新闻的四大发展特点
  17. CentOS7.0系统安全加固实施方案
  18. python 节气_Python开源日志01:pyGregorian2LunarCalendar公历农历转换、阳历阴历转换、二十四节气计算...
  19. 四元数、欧拉角、旋转矩阵、旋转向量之间的转换
  20. 小说阅读翻页分页实现思路

热门文章

  1. 对象转数组的方法(常见三种)
  2. Terraform常用命令行详解
  3. java 怎么产生随机数_Java怎么产生随机数
  4. mysql存储过程自动生成周次数据
  5. linux批量删除croe文件,Creo一键删除旧版本和无用文件 | 坐倚北风
  6. 爱单纯女孩十个必要条件
  7. 用python实现一个计算Fibonacci数的函数
  8. 网络安全等级保护测评——主机安全(三级)详解
  9. 如何在Schlage Connect Smart Lock上启用警报
  10. 【渗透测试】web端姿势-前端利用