次の方法で共有


SqlParameter コンストラクタ (String, SqlDbType, Int32, ParameterDirection, Boolean, Byte, Byte, String, DataRowVersion, Object)

パラメータ名、パラメータの種類、パラメータのサイズ、ParameterDirection、パラメータの精度、パラメータのスケール、ソース列、使用する DataRowVersion、およびパラメータの値を指定して、SqlParameter クラスの新しいインスタンスを初期化します。

名前空間: System.Data.SqlClient
アセンブリ: System.Data (system.data.dll 内)

構文

'宣言
Public Sub New ( _
    parameterName As String, _
    dbType As SqlDbType, _
    size As Integer, _
    direction As ParameterDirection, _
    isNullable As Boolean, _
    precision As Byte, _
    scale As Byte, _
    sourceColumn As String, _
    sourceVersion As DataRowVersion, _
    value As Object _
)
'使用
Dim parameterName As String
Dim dbType As SqlDbType
Dim size As Integer
Dim direction As ParameterDirection
Dim isNullable As Boolean
Dim precision As Byte
Dim scale As Byte
Dim sourceColumn As String
Dim sourceVersion As DataRowVersion
Dim value As Object

Dim instance As New SqlParameter(parameterName, dbType, size, direction, isNullable, precision, scale, sourceColumn, sourceVersion, value)
public SqlParameter (
    string parameterName,
    SqlDbType dbType,
    int size,
    ParameterDirection direction,
    bool isNullable,
    byte precision,
    byte scale,
    string sourceColumn,
    DataRowVersion sourceVersion,
    Object value
)
public:
SqlParameter (
    String^ parameterName, 
    SqlDbType dbType, 
    int size, 
    ParameterDirection direction, 
    bool isNullable, 
    unsigned char precision, 
    unsigned char scale, 
    String^ sourceColumn, 
    DataRowVersion sourceVersion, 
    Object^ value
)
public SqlParameter (
    String parameterName, 
    SqlDbType dbType, 
    int size, 
    ParameterDirection direction, 
    boolean isNullable, 
    byte precision, 
    byte scale, 
    String sourceColumn, 
    DataRowVersion sourceVersion, 
    Object value
)
public function SqlParameter (
    parameterName : String, 
    dbType : SqlDbType, 
    size : int, 
    direction : ParameterDirection, 
    isNullable : boolean, 
    precision : byte, 
    scale : byte, 
    sourceColumn : String, 
    sourceVersion : DataRowVersion, 
    value : Object
)

パラメータ

  • parameterName
    割り当てるパラメータの名前。
  • size
    パラメータの長さ。
  • isNullable
    フィールドの値を null にできる場合は true。それ以外の場合は false
  • precision
    Value を解決するための、小数点の左右の合計桁数。
  • scale
    Value を解決するための、小数部の桁数。
  • sourceColumn
    ソース列の名前。

例外

例外の種類 条件

ArgumentException

dbType パラメータで指定された値は、無効なバックエンド データ型です。

解説

size パラメータと precision パラメータで明示的に設定しなかった場合、SizePrecision は、dbType パラメータの値から推論されます。

使用例

SqlParameter を作成し、そのプロパティの一部を設定する例を次に示します。

Private Sub AddSqlParameter(ByVal command As SqlCommand)

    Dim parameter As New SqlParameter("@Description", _
        SqlDbType.VarChar, 11, ParameterDirection.Input, _
        True, 0, 0, "Description", DataRowVersion.Current, _
        "garden hose")
    parameter.IsNullable = True

    command.Parameters.Add(parameter)
End Sub
private static void AddSqlParameter(SqlCommand command)
{
    SqlParameter parameter = new SqlParameter("@Description", 
        SqlDbType.VarChar, 11, ParameterDirection.Input,
        true, 0, 0, "Description", DataRowVersion.Current, 
        "garden hose");
    parameter.IsNullable = true;

    command.Parameters.Add(parameter);
}

プラットフォーム

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 2.0、1.0

参照

関連項目

SqlParameter クラス
SqlParameter メンバ
System.Data.SqlClient 名前空間

その他の技術情報

ADO.NET でのデータへの接続およびデータの取得
.NET Framework Data Provider for SQL Server の使用