SqlCommand Konstruktory

Definice

Inicializuje novou instanci SqlCommand třídy.

Přetížení

Name Description
SqlCommand()

Inicializuje novou instanci SqlCommand třídy.

SqlCommand(String)

Inicializuje novou instanci SqlCommand třídy s textem dotazu.

SqlCommand(String, SqlConnection)

Inicializuje novou instanci SqlCommand třídy s textem dotazu a .SqlConnection

SqlCommand(String, SqlConnection, SqlTransaction)

Inicializuje novou instanci SqlCommand třídy s textem dotazu, a SqlConnectionSqlTransaction.

SqlCommand(String, SqlConnection, SqlTransaction, SqlCommandColumnEncryptionSetting)

Inicializuje novou instanci SqlCommand třídy se zadaným textem příkazu, připojením, transakcí a nastavením šifrování.

SqlCommand()

Zdroj:
System.Data.SqlClient.notsupported.cs

Inicializuje novou instanci SqlCommand třídy.

public:
 SqlCommand();
public SqlCommand();
Public Sub New ()

Příklady

Následující příklad vytvoří SqlCommand a nastaví CommandTimeout vlastnost.

public void CreateSqlCommand()
{
   SqlCommand command = new SqlCommand();
   command.CommandTimeout = 15;
   command.CommandType = CommandType.Text;
}
Public Sub CreateSqlCommand()
    Dim command As New SqlCommand()
    command.CommandTimeout = 15
    command.CommandType = CommandType.Text
End Sub

Poznámky

Základní konstruktor inicializuje všechna pole na výchozí hodnoty. V následující tabulce jsou uvedeny počáteční hodnoty vlastností pro instanci SqlCommand.

Properties Počáteční hodnota
CommandText prázdný řetězec ("")
CommandTimeout 30
CommandType CommandType.Text
Connection Null

Hodnotu kterékoli z těchto vlastností můžete změnit prostřednictvím samostatného volání vlastnosti.

Viz také

Platí pro

SqlCommand(String)

Zdroj:
System.Data.SqlClient.notsupported.cs

Inicializuje novou instanci SqlCommand třídy s textem dotazu.

public:
 SqlCommand(System::String ^ cmdText);
public SqlCommand(string cmdText);
new System.Data.SqlClient.SqlCommand : string -> System.Data.SqlClient.SqlCommand
Public Sub New (cmdText As String)

Parametry

cmdText
String

Text dotazu.

Příklady

Následující příklad vytvoří příkaz , SqlCommandpředávání textu příkazu.

public void CreateCommand()
 {
    string queryString = "SELECT * FROM Categories ORDER BY CategoryID";
    SqlCommand command = new SqlCommand(queryString);
    command.CommandTimeout = 15;
    command.CommandType = CommandType.Text;
 }
Public Sub CreateCommand()
    Dim queryString As String = "SELECT * FROM Categories ORDER BY CategoryID"
    Dim command As New SqlCommand(queryString)
    command.CommandTimeout = 15
    command.CommandType = CommandType.Text
End Sub

Poznámky

Při vytvoření instance SqlCommand jsou následující vlastnosti pro čtení a zápis nastaveny na počáteční hodnoty.

Properties Počáteční hodnota
CommandText cmdText
CommandTimeout 30
CommandType CommandType.Text
Connection null

Hodnotu kterékoli z těchto vlastností můžete změnit prostřednictvím samostatného volání vlastnosti.

Viz také

Platí pro

SqlCommand(String, SqlConnection)

Zdroj:
System.Data.SqlClient.notsupported.cs

Inicializuje novou instanci SqlCommand třídy s textem dotazu a .SqlConnection

public:
 SqlCommand(System::String ^ cmdText, System::Data::SqlClient::SqlConnection ^ connection);
public SqlCommand(string cmdText, System.Data.SqlClient.SqlConnection connection);
new System.Data.SqlClient.SqlCommand : string * System.Data.SqlClient.SqlConnection -> System.Data.SqlClient.SqlCommand
Public Sub New (cmdText As String, connection As SqlConnection)

Parametry

cmdText
String

Text dotazu.

connection
SqlConnection

SqlConnection představující připojení k instanci SQL Server.

Příklady

Následující příklad vytvoří SqlCommand a nastaví některé jeho vlastnosti.

private static void CreateCommand(string queryString,
    string connectionString)
{
    using (SqlConnection connection = new SqlConnection(
               connectionString))
    {
        SqlCommand command = new SqlCommand(
            queryString, connection);
        connection.Open();
        SqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine(String.Format("{0}, {1}",
                reader[0], reader[1]));
        }
    }
}
Public Sub CreateCommand(ByVal queryString As String, _
  ByVal connectionString As String)
    Using connection As New SqlConnection(connectionString)
        Dim command As New SqlCommand(queryString, connection)

        connection.Open()
        Dim reader As SqlDataReader = command.ExecuteReader()
            While reader.Read()
            Console.WriteLine(String.Format("{0}, {1}", _
                reader(0), reader(1)))
        End While
    End Using
End Sub

Poznámky

V následující tabulce jsou uvedeny počáteční hodnoty vlastností pro instanci SqlCommand.

Properties Počáteční hodnota
CommandText cmdText
CommandTimeout 30
CommandType CommandType.Text
Connection Nová SqlConnection hodnota parametru connection .

Hodnotu některého z těchto parametrů můžete změnit nastavením související vlastnosti.

Viz také

Platí pro

SqlCommand(String, SqlConnection, SqlTransaction)

Zdroj:
System.Data.SqlClient.notsupported.cs

Inicializuje novou instanci SqlCommand třídy s textem dotazu, a SqlConnectionSqlTransaction.

public:
 SqlCommand(System::String ^ cmdText, System::Data::SqlClient::SqlConnection ^ connection, System::Data::SqlClient::SqlTransaction ^ transaction);
public SqlCommand(string cmdText, System.Data.SqlClient.SqlConnection connection, System.Data.SqlClient.SqlTransaction transaction);
new System.Data.SqlClient.SqlCommand : string * System.Data.SqlClient.SqlConnection * System.Data.SqlClient.SqlTransaction -> System.Data.SqlClient.SqlCommand
Public Sub New (cmdText As String, connection As SqlConnection, transaction As SqlTransaction)

Parametry

cmdText
String

Text dotazu.

connection
SqlConnection

SqlConnection představující připojení k instanci SQL Server.

transaction
SqlTransaction

To SqlTransaction , ve kterém se SqlCommand spouští.

Poznámky

V následující tabulce jsou uvedeny počáteční hodnoty vlastností pro instanci SqlCommand.

Properties Počáteční hodnota
CommandText cmdText
CommandTimeout 30
CommandType CommandType.Text
Connection Nová SqlConnection hodnota parametru connection .

Hodnotu některého z těchto parametrů můžete změnit nastavením související vlastnosti.

Viz také

Platí pro

SqlCommand(String, SqlConnection, SqlTransaction, SqlCommandColumnEncryptionSetting)

Inicializuje novou instanci SqlCommand třídy se zadaným textem příkazu, připojením, transakcí a nastavením šifrování.

public:
 SqlCommand(System::String ^ cmdText, System::Data::SqlClient::SqlConnection ^ connection, System::Data::SqlClient::SqlTransaction ^ transaction, System::Data::SqlClient::SqlCommandColumnEncryptionSetting columnEncryptionSetting);
public SqlCommand(string cmdText, System.Data.SqlClient.SqlConnection connection, System.Data.SqlClient.SqlTransaction transaction, System.Data.SqlClient.SqlCommandColumnEncryptionSetting columnEncryptionSetting);
new System.Data.SqlClient.SqlCommand : string * System.Data.SqlClient.SqlConnection * System.Data.SqlClient.SqlTransaction * System.Data.SqlClient.SqlCommandColumnEncryptionSetting -> System.Data.SqlClient.SqlCommand
Public Sub New (cmdText As String, connection As SqlConnection, transaction As SqlTransaction, columnEncryptionSetting As SqlCommandColumnEncryptionSetting)

Parametry

cmdText
String

Text dotazu.

connection
SqlConnection

SqlConnection představující připojení k instanci SQL Server.

transaction
SqlTransaction

To SqlTransaction , ve kterém se SqlCommand spouští.

columnEncryptionSetting
SqlCommandColumnEncryptionSetting

Nastavení šifrování. Další informace naleznete v tématu Always Encrypted.

Platí pro