SqlConnection.CreateCommand 메서드

정의

SqlConnection과 연결된 SqlCommand 개체를 만들고 반환합니다.

public:
 Microsoft::Data::SqlClient::SqlCommand ^ CreateCommand();
public Microsoft.Data.SqlClient.SqlCommand CreateCommand ();
override this.CreateCommand : unit -> Microsoft.Data.SqlClient.SqlCommand
Public Function CreateCommand () As SqlCommand

반환

SqlCommand 개체입니다.

예제

using Microsoft.Data.SqlClient;
public class A
{
    public static void Main()
    {
        using (SqlConnection connection = new SqlConnection("Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI;"))
        {
            connection.Open();
            SqlCommand command = connection.CreateCommand();
            command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID";
            command.CommandTimeout = 15;
            command.CommandType = CommandType.Text;
        }
    }
}

적용 대상