英語で読む

次の方法で共有


SqlConnection.CreateCommand メソッド

定義

SqlConnection に関連付けられている SqlCommand オブジェクトを作成し、返します。

public System.Data.SqlClient.SqlCommand CreateCommand ();

戻り値

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;
      }
   }
}

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0

こちらもご覧ください