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

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

Parameters

commandText
The text of the query.
connection
A SqlConnection object that represents the connection to SQL Server.
Remarks
The following table shows initial property values for an instance of SqlCommand.
Properties Initial value
CommandText commandText
CommandTimeout 30
CommandType System.Data.CommandType.Text
Connection connection
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;");
  string mySelectQuery = "SELECT * FROM Test.Dept";
  SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection);
  myCommand.FetchSize = 100;
}
Public Sub CreateCommand()
  Dim myConnection As New SqlConnection( _
    "User Id=sa;Server=localhost;Initial Catalog=Test;")
  Dim mySelectQuery As String = _
    "SELECT * FROM Test.Dept"
  Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
  myCommand.FetchSize = 100
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also