CreateCommand Method

SqlConnection.CreateCommand Method ()

 

Creates and returns a SqlCommand object associated with the SqlConnection.

Namespace:   System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)

public SqlCommand CreateCommand()

Return Value

Type: System.Data.SqlClient.SqlCommand

A SqlCommand object.

using System.Data;
using System.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;
      }
   }
}

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft