温馨提示×

C#中ParameterDirection参数类型怎么定义

c#
小亿
105
2023-09-26 12:48:36
栏目: 编程语言

在C#中,可以使用System.Data.ParameterDirection枚举定义ParameterDirection参数类型。这个枚举包含以下值:

  1. Input:指定参数是一个输入参数。

  2. Output:指定参数是一个输出参数。

  3. InputOutput:指定参数是一个输入输出参数。

  4. ReturnValue:指定参数是一个返回值参数。

可以在代码中使用这些枚举值来指定ParameterDirection参数类型。例如,以下代码定义了一个命令对象和一个参数对象,并将参数对象的参数类型设置为输入参数:

using System;
using System.Data;
using System.Data.SqlClient;
class Program
{
static void Main()
{
// 创建连接对象
SqlConnection connection = new SqlConnection("Connection String");
// 创建命令对象
SqlCommand command = new SqlCommand("Procedure Name", connection);
command.CommandType = CommandType.StoredProcedure;
// 创建参数对象
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@ParameterName";
parameter.Value = "Parameter Value";
parameter.Direction = ParameterDirection.Input;
// 将参数对象添加到命令对象的参数集合
command.Parameters.Add(parameter);
// 执行命令
connection.Open();
command.ExecuteNonQuery();
connection.Close();
}
}

在上面的代码中,参数对象的Direction属性被设置为ParameterDirection.Input,表示该参数是一个输入参数。

0