添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft Edge More info about Internet Explorer and Microsoft Edge SqlParameter(String, SqlDbType, Int32, ParameterDirection, Boolean, Byte, Byte, String, DataRowVersion, Object)

Initializes a new instance of the SqlParameter class that uses the parameter name, the type of the parameter, the size of the parameter, a ParameterDirection , the precision of the parameter, the scale of the parameter, the source column, a DataRowVersion to use, and the value of the parameter.

SqlParameter(String, SqlDbType, Int32, ParameterDirection, Byte, Byte, String, DataRowVersion, Boolean, Object, String, String, String)

Initializes a new instance of the SqlParameter class that uses the parameter name, the type of the parameter, the length of the parameter the direction, the precision, the scale, the name of the source column, one of the DataRowVersion values, a Boolean for source column mapping, the value of the SqlParameter , the name of the database where the schema collection for this XML instance is located, the owning relational schema where the schema collection for this XML instance is located, and the name of the schema collection for this parameter.

The following example creates a SqlParameter and sets some of its properties.

private static void AddSqlParameter(SqlCommand command) SqlParameter parameter = new SqlParameter(); parameter.ParameterName = "@Description"; parameter.IsNullable = true; parameter.SqlDbType = SqlDbType.VarChar; parameter.Direction = ParameterDirection.Output; parameter.Size = 88; command.Parameters.Add(parameter); Private Sub AddSqlParameter(ByVal command As SqlCommand) Dim parameter As New SqlParameter() With parameter .ParameterName = "@Description" .IsNullable = True .SqlDbType = SqlDbType.VarChar .Direction = ParameterDirection.Output .Size = 88 End With command.Parameters.Add(parameter) End Sub
public:
 SqlParameter(System::String ^ parameterName, System::Data::SqlDbType dbType);
public SqlParameter (string parameterName, System.Data.SqlDbType dbType);
new System.Data.SqlClient.SqlParameter : string * System.Data.SqlDbType -> System.Data.SqlClient.SqlParameter
Public Sub New (parameterName As String, dbType As SqlDbType)

Parameters

The following example creates a SqlParameter and sets some of its properties.

private static void AddSqlParameter(SqlCommand command, string paramValue) SqlParameter parameter = new SqlParameter("@Description", SqlDbType.VarChar); parameter.IsNullable = true; parameter.Direction = ParameterDirection.Output; parameter.Size = 88; parameter.Value = paramValue; command.Parameters.Add(parameter); Private Sub AddSqlParameter(ByVal command As SqlCommand, _ ByVal paramValue As String) Dim parameter As New SqlParameter("@Description", _ SqlDbType.VarChar) With parameter .IsNullable = True .Direction = ParameterDirection.Output .Size = 88 .Value = paramValue End With command.Parameters.Add(parameter) End Sub

Remarks

The data type and, if appropriate, Size and Precision are inferred from the value of the dbType parameter.

  • Commands and Parameters (ADO.NET)
  • DataAdapter Parameters (ADO.NET)
  • Using the .NET Framework Data Provider for SQL Server
  • ADO.NET Overview
  • Applies to

    public:
     SqlParameter(System::String ^ parameterName, System::Object ^ value);
    public SqlParameter (string parameterName, object value);
    new System.Data.SqlClient.SqlParameter : string * obj -> System.Data.SqlClient.SqlParameter
    Public Sub New (parameterName As String, value As Object)

    Parameters

    The following example creates a SqlParameter and sets some of its properties.

    private static void AddSqlParameter(SqlCommand command) SqlParameter parameter = new SqlParameter("@Description", SqlDbType.VarChar, 88, "Description"); parameter.IsNullable = true; parameter.Direction = ParameterDirection.Output; command.Parameters.Add(parameter); Private Sub AddSqlParameter(ByVal command As SqlCommand) Dim parameter As New SqlParameter("@Description", _ SqlDbType.VarChar, 88, "Description") With parameter .IsNullable = True .Direction = ParameterDirection.Output End With command.Parameters.Add(parameter) End Sub

    Remarks

    When you specify an Object in the value parameter, the SqlDbType is inferred from the Microsoft .NET Framework type of the Object .

    Use caution when you use this overload of the SqlParameter constructor to specify integer parameter values. Because this overload takes a value of type Object , you must convert the integral value to an Object type when the value is zero, as the following C# example demonstrates.

    Parameter = new SqlParameter("@pname", (object)0);  
    

    If you do not perform this conversion, the compiler assumes that you are trying to call the SqlParameter(String, SqlDbType) constructor overload.

  • Commands and Parameters (ADO.NET)
  • DataAdapter Parameters (ADO.NET)
  • Using the .NET Framework Data Provider for SQL Server
  • ADO.NET Overview
  • Applies to

    public:
     SqlParameter(System::String ^ parameterName, System::Data::SqlDbType dbType, int size);
    public SqlParameter (string parameterName, System.Data.SqlDbType dbType, int size);
    new System.Data.SqlClient.SqlParameter : string * System.Data.SqlDbType * int -> System.Data.SqlClient.SqlParameter
    Public Sub New (parameterName As String, dbType As SqlDbType, size As Integer)

    Parameters

    The following example creates a SqlParameter and sets some of its properties.

    private static void AddSqlParameter(SqlCommand command, string paramValue) SqlParameter parameter = new SqlParameter("@Description", SqlDbType.VarChar, 88); parameter.IsNullable = true; parameter.Direction = ParameterDirection.Output; parameter.Value = paramValue; command.Parameters.Add(parameter); Private Sub AddSqlParameter(ByVal command As SqlCommand, _ ByVal paramValue As String) Dim parameter As New SqlParameter("@Description", _ SqlDbType.VarChar, 88) With parameter .IsNullable = True .Direction = ParameterDirection.Output .Value = paramValue End With command.Parameters.Add(parameter) End Sub

    Remarks

    The Size is inferred from the value of the dbType parameter if it is not explicitly set in the size parameter.

  • Commands and Parameters (ADO.NET)
  • DataAdapter Parameters (ADO.NET)
  • Using the .NET Framework Data Provider for SQL Server
  • ADO.NET Overview
  • Applies to

    public:
     SqlParameter(System::String ^ parameterName, System::Data::SqlDbType dbType, int size, System::String ^ sourceColumn);
    public SqlParameter (string parameterName, System.Data.SqlDbType dbType, int size, string sourceColumn);
    new System.Data.SqlClient.SqlParameter : string * System.Data.SqlDbType * int * string -> System.Data.SqlClient.SqlParameter
    Public Sub New (parameterName As String, dbType As SqlDbType, size As Integer, sourceColumn As String)

    Parameters

    The following example creates a SqlParameter and sets some of its properties.

    private static void AddSqlParameter(SqlCommand command) SqlParameter parameter = new SqlParameter("@Description", SqlDbType.VarChar, 88, "Description"); parameter.IsNullable = true; parameter.Direction = ParameterDirection.Output; command.Parameters.Add(parameter); Private Sub AddSqlParameter(ByVal command As SqlCommand) Dim parameter As New SqlParameter("@Description", _ SqlDbType.VarChar, 88, "Description") With parameter .IsNullable = True .Direction = ParameterDirection.Output End With command.Parameters.Add(parameter) End Sub

    Remarks

    The Size is inferred from the value of the dbType parameter if it is not explicitly set in the size parameter.

  • Commands and Parameters (ADO.NET)
  • DataAdapter Parameters (ADO.NET)
  • Using the .NET Framework Data Provider for SQL Server
  • ADO.NET Overview
  • Applies to

    public:
     SqlParameter(System::String ^ parameterName, System::Data::SqlDbType dbType, int size, System::Data::ParameterDirection direction, bool isNullable, System::Byte precision, System::Byte scale, System::String ^ sourceColumn, System::Data::DataRowVersion sourceVersion, System::Object ^ value);
    public SqlParameter (string parameterName, System.Data.SqlDbType dbType, int size, System.Data.ParameterDirection direction, bool isNullable, byte precision, byte scale, string sourceColumn, System.Data.DataRowVersion sourceVersion, object value);
    new System.Data.SqlClient.SqlParameter : string * System.Data.SqlDbType * int * System.Data.ParameterDirection * bool * byte * byte * string * System.Data.DataRowVersion * obj -> System.Data.SqlClient.SqlParameter
    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)

    Parameters

    The following example creates a SqlParameter and sets some of its properties.

    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); 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

    Remarks

    The Size and Precision are inferred from the value of the dbType parameter if they are not explicitly set in the size and precision parameters.

  • Commands and Parameters (ADO.NET)
  • DataAdapter Parameters (ADO.NET)
  • Using the .NET Framework Data Provider for SQL Server
  • ADO.NET Overview
  • Applies to

    Initializes a new instance of the SqlParameter class that uses the parameter name, the type of the parameter, the length of the parameter the direction, the precision, the scale, the name of the source column, one of the DataRowVersion values, a Boolean for source column mapping, the value of the SqlParameter, the name of the database where the schema collection for this XML instance is located, the owning relational schema where the schema collection for this XML instance is located, and the name of the schema collection for this parameter.

    public:
     SqlParameter(System::String ^ parameterName, System::Data::SqlDbType dbType, int size, System::Data::ParameterDirection direction, System::Byte precision, System::Byte scale, System::String ^ sourceColumn, System::Data::DataRowVersion sourceVersion, bool sourceColumnNullMapping, System::Object ^ value, System::String ^ xmlSchemaCollectionDatabase, System::String ^ xmlSchemaCollectionOwningSchema, System::String ^ xmlSchemaCollectionName);
    public SqlParameter (string parameterName, System.Data.SqlDbType dbType, int size, System.Data.ParameterDirection direction, byte precision, byte scale, string sourceColumn, System.Data.DataRowVersion sourceVersion, bool sourceColumnNullMapping, object value, string xmlSchemaCollectionDatabase, string xmlSchemaCollectionOwningSchema, string xmlSchemaCollectionName);
    new System.Data.SqlClient.SqlParameter : string * System.Data.SqlDbType * int * System.Data.ParameterDirection * byte * byte * string * System.Data.DataRowVersion * bool * obj * string * string * string -> System.Data.SqlClient.SqlParameter
    Public Sub New (parameterName As String, dbType As SqlDbType, size As Integer, direction As ParameterDirection, precision As Byte, scale As Byte, sourceColumn As String, sourceVersion As DataRowVersion, sourceColumnNullMapping As Boolean, value As Object, xmlSchemaCollectionDatabase As String, xmlSchemaCollectionOwningSchema As String, xmlSchemaCollectionName As String)

    Parameters

  • SQL Server Data Types and ADO.NET
  • Commands and Parameters (ADO.NET)
  • DataAdapter Parameters (ADO.NET)
  • Using the .NET Framework Data Provider for SQL Server
  • ADO.NET Overview
  • Applies to