SqlCommand クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
SQL Server データベースに対して実行するTransact-SQLステートメントまたはストアド プロシージャを表します。 このクラスは継承できません。
public ref class SqlCommand sealed : System::Data::Common::DbCommand, ICloneable
public sealed class SqlCommand : System.Data.Common.DbCommand, ICloneable
type SqlCommand = class
inherit DbCommand
interface ICloneable
Public NotInheritable Class SqlCommand
Inherits DbCommand
Implements ICloneable
- 継承
-
SqlCommand
- 実装
例
次の例では、 SqlConnection、 SqlCommand、および SqlDataReaderを作成します。 この例では、データを読み取り、コンソールに書き込みます。 最後に、SqlDataReaderを閉じ、SqlConnection コード ブロックを終了すると、Usingを閉じます。
using System;
using System.Data;
using Microsoft.Data.SqlClient;
namespace SqlCommandCS
{
class Program
{
static void Main()
{
string str = "Data Source=(local);Initial Catalog=Northwind;"
+ "Integrated Security=SSPI";
ReadOrderData(str);
}
private static void ReadOrderData(string connectionString)
{
string queryString =
"SELECT OrderID, CustomerID FROM dbo.Orders;";
using (SqlConnection connection = new SqlConnection(
connectionString))
{
SqlCommand command = new SqlCommand(
queryString, connection);
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(String.Format("{0}, {1}",
reader[0], reader[1]));
}
}
}
}
次の例では、さまざまな種類の SqlCommand オブジェクトを作成して実行する方法を示します。
まず、次のスクリプトを実行して、サンプル データベースを作成する必要があります。
USE [master]
GO
CREATE DATABASE [MySchool]
GO
USE [MySchool]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[CourseExtInfo] @CourseId int
as
select c.CourseID,c.Title,c.Credits,d.Name as DepartmentName
from Course as c left outer join Department as d on c.DepartmentID=d.DepartmentID
where c.CourseID=@CourseId
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[DepartmentInfo] @DepartmentId int,@CourseCount int output
as
select @CourseCount=Count(c.CourseID)
from course as c
where c.DepartmentID=@DepartmentId
select d.DepartmentID,d.Name,d.Budget,d.StartDate,d.Administrator
from Department as d
where d.DepartmentID=@DepartmentId
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create PROCEDURE [dbo].[GetDepartmentsOfSpecifiedYear]
@Year int,@BudgetSum money output
AS
BEGIN
SELECT @BudgetSum=SUM([Budget])
FROM [MySchool].[dbo].[Department]
Where YEAR([StartDate])=@Year
SELECT [DepartmentID]
,[Name]
,[Budget]
,[StartDate]
,[Administrator]
FROM [MySchool].[dbo].[Department]
Where YEAR([StartDate])=@Year
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Course]([CourseID] [nvarchar](10) NOT NULL,
[Year] [smallint] NOT NULL,
[Title] [nvarchar](100) NOT NULL,
[Credits] [int] NOT NULL,
[DepartmentID] [int] NOT NULL,
CONSTRAINT [PK_Course] PRIMARY KEY CLUSTERED
(
[CourseID] ASC,
[Year] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Department]([DepartmentID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[Budget] [money] NOT NULL,
[StartDate] [datetime] NOT NULL,
[Administrator] [int] NULL,
CONSTRAINT [PK_Department] PRIMARY KEY CLUSTERED
(
[DepartmentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Person]([PersonID] [int] IDENTITY(1,1) NOT NULL,
[LastName] [nvarchar](50) NOT NULL,
[FirstName] [nvarchar](50) NOT NULL,
[HireDate] [datetime] NULL,
[EnrollmentDate] [datetime] NULL,
CONSTRAINT [PK_School.Student] PRIMARY KEY CLUSTERED
(
[PersonID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StudentGrade]([EnrollmentID] [int] IDENTITY(1,1) NOT NULL,
[CourseID] [nvarchar](10) NOT NULL,
[StudentID] [int] NOT NULL,
[Grade] [decimal](3, 2) NOT NULL,
CONSTRAINT [PK_StudentGrade] PRIMARY KEY CLUSTERED
(
[EnrollmentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[EnglishCourse]
as
select c.CourseID,c.Title,c.Credits,c.DepartmentID
from Course as c join Department as d on c.DepartmentID=d.DepartmentID
where d.Name=N'English'
GO
INSERT [dbo].[Course] ([CourseID], [Year], [Title], [Credits], [DepartmentID]) VALUES (N'C1045', 2012, N'Calculus', 4, 7)
INSERT [dbo].[Course] ([CourseID], [Year], [Title], [Credits], [DepartmentID]) VALUES (N'C1061', 2012, N'Physics', 4, 1)
INSERT [dbo].[Course] ([CourseID], [Year], [Title], [Credits], [DepartmentID]) VALUES (N'C2021', 2012, N'Composition', 3, 2)
INSERT [dbo].[Course] ([CourseID], [Year], [Title], [Credits], [DepartmentID]) VALUES (N'C2042', 2012, N'Literature', 4, 2)
SET IDENTITY_INSERT [dbo].[Department] ON
INSERT [dbo].[Department] ([DepartmentID], [Name], [Budget], [StartDate], [Administrator]) VALUES (1, N'Engineering', 350000.0000, CAST(0x0000999C00000000 AS DateTime), 2)
INSERT [dbo].[Department] ([DepartmentID], [Name], [Budget], [StartDate], [Administrator]) VALUES (2, N'English', 120000.0000, CAST(0x0000999C00000000 AS DateTime), 6)
INSERT [dbo].[Department] ([DepartmentID], [Name], [Budget], [StartDate], [Administrator]) VALUES (4, N'Economics', 200000.0000, CAST(0x0000999C00000000 AS DateTime), 4)
INSERT [dbo].[Department] ([DepartmentID], [Name], [Budget], [StartDate], [Administrator]) VALUES (7, N'Mathematics', 250024.0000, CAST(0x0000999C00000000 AS DateTime), 3)
SET IDENTITY_INSERT [dbo].[Department] OFF
SET IDENTITY_INSERT [dbo].[Person] ON
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (1, N'Hu', N'Nan', NULL, CAST(0x0000A0BF00000000 AS DateTime))
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (2, N'Norman', N'Laura', NULL, CAST(0x0000A0BF00000000 AS DateTime))
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (3, N'Olivotto', N'Nino', NULL, CAST(0x0000A0BF00000000 AS DateTime))
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (4, N'Anand', N'Arturo', NULL, CAST(0x0000A0BF00000000 AS DateTime))
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (5, N'Jai', N'Damien', NULL, CAST(0x0000A0BF00000000 AS DateTime))
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (6, N'Holt', N'Roger', CAST(0x000097F100000000 AS DateTime), NULL)
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (7, N'Martin', N'Randall', CAST(0x00008B1A00000000 AS DateTime), NULL)
SET IDENTITY_INSERT [dbo].[Person] OFF
SET IDENTITY_INSERT [dbo].[StudentGrade] ON
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (1, N'C1045', 1, CAST(3.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (2, N'C1045', 2, CAST(3.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (3, N'C1045', 3, CAST(2.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (4, N'C1045', 4, CAST(4.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (5, N'C1045', 5, CAST(3.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (6, N'C1061', 1, CAST(4.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (7, N'C1061', 3, CAST(3.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (8, N'C1061', 4, CAST(2.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (9, N'C1061', 5, CAST(1.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (10, N'C2021', 1, CAST(2.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (11, N'C2021', 2, CAST(3.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (12, N'C2021', 4, CAST(3.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (13, N'C2021', 5, CAST(3.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (14, N'C2042', 1, CAST(2.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (15, N'C2042', 2, CAST(3.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (16, N'C2042', 3, CAST(4.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (17, N'C2042', 5, CAST(3.00 AS Decimal(3, 2)))
SET IDENTITY_INSERT [dbo].[StudentGrade] OFF
ALTER TABLE [dbo].[Course] WITH CHECK ADD CONSTRAINT [FK_Course_Department] FOREIGN KEY([DepartmentID])
REFERENCES [dbo].[Department] ([DepartmentID])
GO
ALTER TABLE [dbo].[Course] CHECK CONSTRAINT [FK_Course_Department]
GO
ALTER TABLE [dbo].[StudentGrade] WITH CHECK ADD CONSTRAINT [FK_StudentGrade_Student] FOREIGN KEY([StudentID])
REFERENCES [dbo].[Person] ([PersonID])
GO
ALTER TABLE [dbo].[StudentGrade] CHECK CONSTRAINT [FK_StudentGrade_Student]
GO
次に、次をコンパイルして実行します。
using System;
using System.Data;
using Microsoft.Data.SqlClient;
using System.Threading.Tasks;
class Program
{
static class SqlHelper
{
// Set the connection, command, and then execute the command with non query.
public static Int32 ExecuteNonQuery(String connectionString, String commandText,
CommandType commandType, params SqlParameter[] parameters)
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand(commandText, conn))
{
// There're three command types: StoredProcedure, Text, TableDirect. The TableDirect
// type is only for OLE DB.
cmd.CommandType = commandType;
cmd.Parameters.AddRange(parameters);
conn.Open();
return cmd.ExecuteNonQuery();
}
}
}
// Set the connection, command, and then execute the command and only return one value.
public static Object ExecuteScalar(String connectionString, String commandText,
CommandType commandType, params SqlParameter[] parameters)
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand(commandText, conn))
{
cmd.CommandType = commandType;
cmd.Parameters.AddRange(parameters);
conn.Open();
return cmd.ExecuteScalar();
}
}
}
// Set the connection, command, and then execute the command with query and return the reader.
public static SqlDataReader ExecuteReader(String connectionString, String commandText,
CommandType commandType, params SqlParameter[] parameters)
{
SqlConnection conn = new SqlConnection(connectionString);
using (SqlCommand cmd = new SqlCommand(commandText, conn))
{
cmd.CommandType = commandType;
cmd.Parameters.AddRange(parameters);
conn.Open();
// When using CommandBehavior.CloseConnection, the connection will be closed when the
// IDataReader is closed.
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return reader;
}
}
}
static void Main(string[] args)
{
String connectionString = "Data Source=(local);Initial Catalog=MySchool;Integrated Security=True;";
CountCourses(connectionString, 2012);
Console.WriteLine();
Console.WriteLine("Following result is the departments that started from 2007:");
GetDepartments(connectionString, 2007);
Console.WriteLine();
Console.WriteLine("Add the credits when the credits of course is lower than 4.");
AddCredits(connectionString, 4);
Console.WriteLine();
Console.WriteLine("Please press any key to exit...");
Console.ReadKey();
}
static void CountCourses(String connectionString, Int32 year)
{
String commandText = "Select Count([CourseID]) FROM [MySchool].[dbo].[Course] Where Year=@Year";
SqlParameter parameterYear = new SqlParameter("@Year", SqlDbType.Int);
parameterYear.Value = year;
Object oValue = SqlHelper.ExecuteScalar(connectionString, commandText, CommandType.Text, parameterYear);
Int32 count;
if (Int32.TryParse(oValue.ToString(), out count))
Console.WriteLine("There {0} {1} course{2} in {3}.", count > 1 ? "are" : "is", count, count > 1 ? "s" : null, year);
}
// Display the Departments that start from the specified year.
static void GetDepartments(String connectionString, Int32 year)
{
String commandText = "dbo.GetDepartmentsOfSpecifiedYear";
// Specify the year of StartDate
SqlParameter parameterYear = new SqlParameter("@Year", SqlDbType.Int);
parameterYear.Value = year;
// When the direction of parameter is set as Output, you can get the value after
// executing the command.
SqlParameter parameterBudget = new SqlParameter("@BudgetSum", SqlDbType.Money);
parameterBudget.Direction = ParameterDirection.Output;
using (SqlDataReader reader = SqlHelper.ExecuteReader(connectionString, commandText,
CommandType.StoredProcedure, parameterYear, parameterBudget))
{
Console.WriteLine("{0,-20}{1,-20}{2,-20}{3,-20}", "Name", "Budget", "StartDate",
"Administrator");
while (reader.Read())
{
Console.WriteLine("{0,-20}{1,-20:C}{2,-20:d}{3,-20}", reader["Name"],
reader["Budget"], reader["StartDate"], reader["Administrator"]);
}
}
Console.WriteLine("{0,-20}{1,-20:C}", "Sum:", parameterBudget.Value);
}
// If credits of course is lower than the certain value, the method will add the credits.
static void AddCredits(String connectionString, Int32 creditsLow)
{
String commandText = "Update [MySchool].[dbo].[Course] Set Credits=Credits+1 Where Credits<@Credits";
SqlParameter parameterCredits = new SqlParameter("@Credits", creditsLow);
Int32 rows = SqlHelper.ExecuteNonQuery(connectionString, commandText, CommandType.Text, parameterCredits);
Console.WriteLine("{0} row{1} {2} updated.", rows, rows > 1 ? "s" : null, rows > 1 ? "are" : "is");
}
}
注釈
SqlCommandのインスタンスが作成されると、読み取り/書き込みプロパティは初期値に設定されます。 これらの値の一覧については、 SqlCommand コンストラクターを参照してください。
SqlCommand には、SQL Server データベースでコマンドを実行するための次のメソッドが用意されています。
| 項目 | Description |
|---|---|
| BeginExecuteNonQuery | この SqlCommandによって記述される Transact-SQL ステートメントまたはストアド プロシージャの非同期実行を開始します。通常は、INSERT、DELETE、UPDATE、SET ステートメントなどのコマンドを実行します。 BeginExecuteNonQueryの各呼び出しは、通常は別のスレッドで、操作を完了するEndExecuteNonQueryの呼び出しとペアにする必要があります。 |
| BeginExecuteReader | この SqlCommand で記述されている Transact-SQL ステートメントまたはストアド プロシージャの非同期実行を開始し、サーバーから 1 つ以上の結果セットを取得します。 BeginExecuteReaderの各呼び出しは、通常は別のスレッドで、操作を完了するEndExecuteReaderの呼び出しとペアにする必要があります。 |
| BeginExecuteXmlReader | この SqlCommandで記述されている Transact-SQL ステートメントまたはストアド プロシージャの非同期実行を開始します。
BeginExecuteXmlReaderの各呼び出しは、EndExecuteXmlReaderの呼び出しとペアになっている必要があります。この呼び出しは、通常は別のスレッドで操作を完了し、XmlReader オブジェクトを返します。 |
| ExecuteReader | 行を返すコマンドを実行します。 パフォーマンスを向上させるために、 ExecuteReader は、Transact-SQL sp_executesql システム ストアド プロシージャを使用してコマンドを呼び出します。 したがって、 ExecuteReader は、SET ステートメントなどのコマンドを実行するために使用する場合 Transact-SQL 効果がない可能性があります。 |
| ExecuteNonQuery | Transact-SQL INSERT、DELETE、UPDATE、SET ステートメントなどのコマンドを実行します。 |
| ExecuteScalar | データベースから単一の値 (集計値など) を取得します。 |
| ExecuteXmlReader | CommandTextをConnectionに送信し、XmlReader オブジェクトをビルドします。 |
CommandText プロパティをリセットし、SqlCommand オブジェクトを再利用できます。 ただし、新しいコマンドまたは前のコマンドを実行するには、 SqlDataReader を閉じる必要があります。
SqlExceptionを実行するメソッドによってSqlCommandが生成された場合、重大度レベルが 19 以下の場合、SqlConnectionは開いたままです。 重大度レベルが 20 以上の場合、サーバーは通常、 SqlConnectionを閉じます。 ただし、ユーザーは接続を再度開いて続行できます。
Note
名前なし (序数とも呼ばれます) パラメーターは、.NET Framework Data Provider for SQL Server ではサポートされていません。
コンストラクター
| 名前 | 説明 |
|---|---|
| SqlCommand() |
SqlCommand クラスの新しいインスタンスを初期化します。 |
| SqlCommand(String, SqlConnection, SqlTransaction, SqlCommandColumnEncryptionSetting) |
指定したコマンド テキスト、接続、トランザクション、および暗号化設定を使用して、 SqlCommand クラスの新しいインスタンスを初期化します。 |
| SqlCommand(String, SqlConnection, SqlTransaction) |
クエリ、SqlCommand、およびSqlConnectionのテキストを使用して、SqlTransaction クラスの新しいインスタンスを初期化します。 |
| SqlCommand(String, SqlConnection) |
クエリのテキストとSqlCommandを使用して、SqlConnection クラスの新しいインスタンスを初期化します。 |
| SqlCommand(String) |
クエリのテキストを使用して、 SqlCommand クラスの新しいインスタンスを初期化します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| ColumnEncryptionSetting |
このコマンドの列暗号化設定を取得します。 |
| CommandText |
データ ソースで実行する Transact-SQL ステートメント、テーブル名、またはストアド プロシージャを取得または設定します。 |
| CommandTimeout |
コマンドの実行の試行を終了してエラーを生成するまでの待機時間 (秒単位) を取得または設定します。 既定値は 30 秒です。 |
| CommandType |
CommandText プロパティの解釈方法を示す値を取得または設定します。 |
| Connection |
SqlConnectionのこのインスタンスによって使用されるSqlCommandを取得または設定します。 |
| DesignTimeVisible |
Windows フォーム デザイナー コントロールにコマンド オブジェクトを表示するかどうかを示す値を取得または設定します。 |
| EnableOptimizedParameterBinding |
コマンドをSQL Serverに送信するときに Output と InputOutput の方向を無効にして、コマンド オブジェクトがパラメーターのパフォーマンスを最適化するかどうかを示す値を取得または設定します。 |
| Notification |
このコマンドにバインドされた SqlNotificationRequest オブジェクトを指定する値を取得または設定します。 |
| NotificationAutoEnlist |
アプリケーションが共通の SqlDependency オブジェクトからクエリ通知を自動的に受信するかどうかを示す値を取得または設定します。 |
| Parameters |
SqlParameterCollection を取得します。 |
| RetryLogicProvider |
このコマンドにバインドされた SqlRetryLogicBaseProvider オブジェクトを指定する値を取得または設定します。 |
| Transaction |
SqlTransactionが実行されるSqlCommandを取得または設定します。 |
| UpdatedRowSource |
DataRowの |
メソッド
| 名前 | 説明 |
|---|---|
| BeginExecuteNonQuery() |
この SqlCommandで記述されている Transact-SQL ステートメントまたはストアド プロシージャの非同期実行を開始します。 |
| BeginExecuteNonQuery(AsyncCallback, Object) |
コールバック プロシージャと状態情報を指定して、この SqlCommandで記述されている Transact-SQL ステートメントまたはストアド プロシージャの非同期実行を開始します。 |
| BeginExecuteReader() |
この SqlCommandで記述されている Transact-SQL ステートメントまたはストアド プロシージャの非同期実行を開始し、サーバーから 1 つ以上の結果セットを取得します。 |
| BeginExecuteReader(AsyncCallback, Object, CommandBehavior) |
次のいずれかを使用して、この SqlCommand で記述されている Transact-SQL ステートメントまたはストアド プロシージャの非同期実行を開始します。
|
| BeginExecuteReader(AsyncCallback, Object) |
この SqlCommand によって記述される Transact-SQL ステートメントまたはストアド プロシージャの非同期実行を開始し、コールバック プロシージャを使用して結果を XmlReader オブジェクトとして返します。 |
| BeginExecuteReader(CommandBehavior) |
SqlCommand値のいずれかを使用して、このCommandBehaviorで記述されている Transact-SQL ステートメントまたはストアド プロシージャの非同期実行を開始します。 |
| BeginExecuteXmlReader() |
この SqlCommand で記述されている Transact-SQL ステートメントまたはストアド プロシージャの非同期実行を開始し、結果を XmlReader オブジェクトとして返します。 |
| BeginExecuteXmlReader(AsyncCallback, Object) |
この SqlCommand によって記述される Transact-SQL ステートメントまたはストアド プロシージャの非同期実行を開始し、コールバック プロシージャを使用して結果を XmlReader オブジェクトとして返します。 |
| Cancel() |
SqlCommandの実行を取り消そうとします。 |
| Clone() |
現在のインスタンスのコピーである新しい SqlCommand オブジェクトを作成します。 |
| CreateParameter() |
SqlParameter オブジェクトの新しいインスタンスを作成します。 |
| EndExecuteNonQuery(IAsyncResult) |
Transact-SQL ステートメントの非同期実行を完了します。 |
| EndExecuteReader(IAsyncResult) |
Transact-SQL ステートメントの非同期実行を終了し、要求された SqlDataReader を返します。 |
| EndExecuteXmlReader(IAsyncResult) |
Transact-SQL ステートメントの非同期実行を完了し、要求されたデータを XML として返します。 |
| ExecuteNonQuery() |
接続に対して Transact-SQL ステートメントを実行し、影響を受けた行数を返します。 |
| ExecuteNonQueryAsync(CancellationToken) |
ExecuteNonQuery()の非同期バージョン。接続に対して Transact-SQL ステートメントを実行し、影響を受けた行数を返します。 キャンセル トークンを使用して、コマンドのタイムアウトが経過する前に操作を破棄するように要求できます。 例外は、返された Task オブジェクトを介して報告されます。 |
| ExecuteReader() |
CommandTextをConnectionに送信し、SqlDataReaderをビルドします。 |
| ExecuteReader(CommandBehavior) |
CommandTextをConnectionに送信し、SqlDataReader値のいずれかを使用してCommandBehaviorを構築します。 |
| ExecuteReaderAsync() |
ExecuteReader()の非同期バージョン。CommandTextをConnectionに送信し、SqlDataReaderをビルドします。 例外は、返された Task オブジェクトを介して報告されます。 |
| ExecuteReaderAsync(CancellationToken) |
ExecuteReader()の非同期バージョン。CommandTextをConnectionに送信し、SqlDataReaderをビルドします。 キャンセル トークンを使用して、コマンドのタイムアウトが経過する前に操作を破棄するように要求できます。 例外は、返された Task オブジェクトを介して報告されます。 |
| ExecuteReaderAsync(CommandBehavior, CancellationToken) |
ExecuteReader(CommandBehavior)の非同期バージョン。CommandTextをConnectionに送信し、SqlDataReaderをビルドします。キャンセル トークンを使用して、コマンドタイムアウトが経過する前に操作を破棄するように要求できます。 例外は、返された Task オブジェクトを介して報告されます。 |
| ExecuteReaderAsync(CommandBehavior) |
ExecuteReader(CommandBehavior)をCommandTextに送信し、Connectionをビルドする、SqlDataReaderの非同期バージョン。 例外は、返された Task オブジェクトを介して報告されます。 |
| ExecuteScalar() |
クエリを実行し、クエリによって返される結果セットの最初の行の最初の列を返します。 追加の列または行は無視されます。 |
| ExecuteScalarAsync(CancellationToken) |
クエリを非同期的に実行し、クエリによって返される結果セットの最初の行の最初の列を返す、 ExecuteScalar()の非同期バージョン。 追加の列または行は無視されます。 キャンセル トークンを使用して、コマンドのタイムアウトが経過する前に操作を破棄するように要求できます。 例外は、返された Task オブジェクトを介して報告されます。 |
| ExecuteXmlReader() |
CommandTextをConnectionに送信し、XmlReader オブジェクトをビルドします。 |
| ExecuteXmlReaderAsync() |
ExecuteXmlReader()の非同期バージョン。CommandTextをConnectionに送信し、XmlReader オブジェクトをビルドします。 例外は、返された Task オブジェクトを介して報告されます。 |
| ExecuteXmlReaderAsync(CancellationToken) |
ExecuteXmlReader()の非同期バージョン。CommandTextをConnectionに送信し、XmlReader オブジェクトをビルドします。 キャンセル トークンを使用して、コマンドのタイムアウトが経過する前に操作を破棄するように要求できます。 例外は、返された Task オブジェクトを介して報告されます。 |
| Prepare() |
SQL Server のインスタンスに準備されたバージョンのコマンドを作成します。 |
| RegisterColumnEncryptionKeyStoreProvidersOnCommand(IDictionary<String,SqlColumnEncryptionKeyStoreProvider>) |
SqlCommand インスタンスに暗号化キー ストア プロバイダーを登録します。 この関数が呼び出された場合、 RegisterColumnEncryptionKeyStoreProviders(IDictionary<String,SqlColumnEncryptionKeyStoreProvider>) または RegisterColumnEncryptionKeyStoreProvidersOnConnection(IDictionary<String,SqlColumnEncryptionKeyStoreProvider>) メソッドを使用して登録されたプロバイダーは無視されます。 この関数は複数回呼び出すことができます。 これにより、ディクショナリの簡易コピーが行われ、設定後にアプリでカスタム プロバイダー リストを変更できなくなります。 |
| ResetCommandTimeout() |
CommandTimeout プロパティを既定値にリセットします。 |
イベント
| 名前 | 説明 |
|---|---|
| StatementCompleted |
Transact-SQL ステートメントの実行が完了したときに発生します。 |
明示的なインターフェイスの実装
| 名前 | 説明 |
|---|---|
| ICloneable.Clone() |
SQL Server データベースに対して実行するTransact-SQLステートメントまたはストアド プロシージャを表します。 このクラスは継承できません。 |