SqlConnection.CreateCommand 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立並傳回與 SqlConnection 關聯的 SqlCommand 物件。
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
傳回
SqlCommand 物件。
範例
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
適用於
另請參閱
- ADO.NET 概觀 \(部分機器翻譯\)