SqlConnection.CreateCommand Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates and returns a SqlCommand object associated with the SqlConnection.
public:
System::Data::SqlClient::SqlCommand ^ CreateCommand();
public System.Data.SqlClient.SqlCommand CreateCommand ();
override this.CreateCommand : unit -> System.Data.SqlClient.SqlCommand
member this.CreateCommand : unit -> System.Data.SqlClient.SqlCommand
Public Function CreateCommand () As SqlCommand
Returns
A SqlCommand object.
Examples
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;
}
}
}
Imports System.Data
Imports System.Data.SqlClient
Public Class A
Public Shared Sub Main()
Using connection As New SqlConnection("Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI;")
connection.Open()
Dim command As SqlCommand = connection.CreateCommand()
command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"
command.CommandTimeout = 15
command.CommandType = CommandType.Text
End Using
End Sub
End Class
Applies to
See also
Colaborați cu noi pe GitHub
Sursa pentru acest conținut poate fi găsită pe GitHub, unde puteți, de asemenea, să creați și să consultați probleme și solicitări de tragere. Pentru mai multe informații, consultați ghidul nostru pentru colaboratori.