dotConnect for SQL Server Documentation
Devart.Data.SqlServer Namespace / SqlCommand Class / SqlCommand Constructor / SqlCommand Constructor(String,SqlConnection,SqlTransaction)
The text of the query.
A SqlConnection object that represents the connection to SQL Server.
SqlTransaction object used to perform transactions with this SqlCommand object.
Example

In This Topic
    SqlCommand Constructor(String,SqlConnection,SqlTransaction)
    In This Topic
    Initializes a new instance of the SqlCommand class with the text of the query, a %% object, and the SqlTransaction.
    Syntax
    'Declaration
     
    Public Function New( _
       ByVal commandText As String, _
       ByVal connection As SqlConnection, _
       ByVal transaction As SqlTransaction _
    )
    public SqlCommand( 
       string commandText,
       SqlConnection connection,
       SqlTransaction transaction
    )

    Parameters

    commandText
    The text of the query.
    connection
    A SqlConnection object that represents the connection to SQL Server.
    transaction
    SqlTransaction object used to perform transactions with this SqlCommand object.
    Remarks
    The following table shows initial property values for an instance of this implementation of the SqlCommand.
    Properties Initial value
    CommandText commandText
    CommandTimeout 30
    CommandType System.Data.CommandType.Text
    Connection connection

    You can change the value for any of these parameters by setting the related property.

    Example
    The following example creates a SqlCommand and sets some of its properties.
    public void CreateCommand()
    {
      SqlConnection myConnection = new SqlConnection(
          "User Id=sa;Server=localhost;Initial Catalog=Test;");
      myConnection.Open();
      SqlTransaction myTrans = myConnection.BeginTransaction();
      string mySelectQuery = "SELECT * FROM Test.Dept";
      SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection,myTrans);
      myCommand.FetchSize = 100
    }
    Public Sub CreateCommand()
      Dim myConnection As New SqlConnection( _
        "User Id=sa;Server=localhost;Initial Catalog=Test;")
      myConnection.Open()
      Dim myTrans As SqlTransaction = myConnection.BeginTransaction()
      Dim mySelectQuery As String = _
        "SELECT * FROM Test.Dept"
      Dim myCommand As New SqlCommand(mySelectQuery, myConnection, myTrans)
      myCommand.FetchSize = 100
    End Sub
    See Also