SqlCommand 클래스

정의

SQL Server 데이터베이스에 대해 실행할 Transact-SQL 문이나 저장 프로시저를 나타냅니다. 이 클래스는 상속될 수 없습니다.

public ref class SqlCommand sealed : System::Data::Common::DbCommand, ICloneable
public ref class SqlCommand sealed : System::Data::Common::DbCommand
public ref class SqlCommand sealed : System::ComponentModel::Component, ICloneable, IDisposable, System::Data::IDbCommand
public sealed class SqlCommand : System.Data.Common.DbCommand, ICloneable
public sealed class SqlCommand : System.Data.Common.DbCommand
public sealed class SqlCommand : System.ComponentModel.Component, ICloneable, IDisposable, System.Data.IDbCommand
type SqlCommand = class
    inherit DbCommand
    interface ICloneable
type SqlCommand = class
    inherit DbCommand
type SqlCommand = class
    inherit Component
    interface IDbCommand
    interface IDisposable
    interface ICloneable
Public NotInheritable Class SqlCommand
Inherits DbCommand
Implements ICloneable
Public NotInheritable Class SqlCommand
Inherits DbCommand
Public NotInheritable Class SqlCommand
Inherits Component
Implements ICloneable, IDbCommand, IDisposable
상속
SqlCommand
상속
상속
구현

예제

다음 예제에서는 , 및 를 SqlCommandSqlDataReader만듭니다SqlConnection. 이 예제에서는 데이터를 읽고 콘솔에 기록합니다. 마지막으로, 이 예제는 코드 블록을 종료할 때 를 닫은 다음 SqlConnectionUsingSqlDataReader 습니다.

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]));
            }
        }
    }
}
Public Sub ReadOrderData(ByVal connectionString As String)
    Dim queryString As String = _
        "SELECT OrderID, CustomerID FROM dbo.Orders;"
    Using connection As New SqlConnection(connectionString)
        Dim command As New SqlCommand(queryString, connection)
        connection.Open()
        Dim reader As SqlDataReader = command.ExecuteReader()
        Try
            While reader.Read()
                Console.WriteLine(String.Format("{0}, {1}", _
                    reader(0), reader(1)))
            End While
        Finally
            ' Always call Close when done reading.
            reader.Close()
        End Try
    End Using
End Sub

다음 샘플에서는 다양한 유형의 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 System.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;Asynchronous Processing=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");
   }
}

설명

의 instance SqlCommand 만들면 읽기/쓰기 속성이 초기 값으로 설정됩니다. 이러한 값의 목록을 보려면 참조는 SqlCommand 생성자입니다.

SqlCommand는 SQL Server 데이터베이스에서 명령을 실행하기 위한 다음 메서드를 제공합니다.

항목 Description
BeginExecuteNonQuery 일반적으로 INSERT, DELETE, UPDATE 및 SET 문과 같은 명령을 실행하는 이 SqlCommand에서 설명하는 Transact-SQL 문 또는 저장 프로시저의 비동기 실행을 시작합니다. 에 대한 BeginExecuteNonQuery 각 호출은 일반적으로 별도의 스레드에서 작업을 완료하는 에 대한 호출 EndExecuteNonQuery 과 페어링되어야 합니다.
BeginExecuteReader 이에 설명 SqlCommand 된 Transact-SQL 문 또는 저장 프로시저의 비동기 실행을 시작하고 서버에서 하나 이상의 결과 집합을 검색합니다. 에 대한 BeginExecuteReader 각 호출은 일반적으로 별도의 스레드에서 작업을 완료하는 에 대한 호출 EndExecuteReader 과 페어링되어야 합니다.
BeginExecuteXmlReader SqlCommand가 설명하는 저장 프로시저 또는 Transact-SQL 문의 비동기 실행을 시작합니다. 에 대한 BeginExecuteXmlReader 각 호출은 일반적으로 별도의 스레드에서 작업을 완료하고 개체를 반환 XmlReader 하는 에 대한 호출EndExecuteXmlReader과 페어링되어야 합니다.
ExecuteReader 행을 반환하는 명령을 실행합니다. 성능을 향상시키려면 ExecuteReader Transact-SQL sp_executesql 시스템 저장 프로시저를 사용하여 명령을 호출합니다. 따라서 Transact-SQL ExecuteReader SET 문과 같은 명령을 실행하는 데 사용할 경우 원하는 효과가 없을 수 있습니다.
ExecuteNonQuery Transact-SQL INSERT, DELETE, UPDATE 및 SET 문과 같은 명령을 실행합니다.
ExecuteScalar 데이터베이스에서 단일 값(예: 집계 값)을 검색합니다.
ExecuteXmlReader CommandTextConnection에 보내고, XmlReader 개체를 빌드합니다.

속성을 재설정 CommandText 하고 개체를 SqlCommand 다시 사용할 수 있습니다. 그러나 새 명령이나 이전 명령을 실행하려면 먼저 를 닫 SqlDataReader 아야 합니다.

SqlException 실행하는 SqlCommandSqlConnection 메서드에서 가 생성되는 경우 심각도 수준이 19 이하일 때 는 열린 상태로 유지됩니다. 심각도 수준이 20 이상인 경우 서버는 일반적으로 를 SqlConnection닫습니다. 그러나 사용자는 연결을 다시 열고 계속할 수 있습니다.

참고

서수라고도 하는 nameless 매개 변수는 SQL Server 대한 .NET Framework 데이터 공급자에서 지원되지 않습니다.

생성자

SqlCommand()

SqlCommand 클래스의 새 인스턴스를 초기화합니다.

SqlCommand(String)

쿼리 텍스트를 사용하여 SqlCommand 클래스의 새 인스턴스를 초기화합니다.

SqlCommand(String, SqlConnection)

쿼리의 텍스트와 SqlConnection을 사용하여 SqlCommand 클래스의 새 인스턴스를 초기화합니다.

SqlCommand(String, SqlConnection, SqlTransaction)

쿼리의 텍스트, SqlConnectionSqlTransaction을 사용하여 SqlCommand 클래스의 새 인스턴스를 초기화합니다.

SqlCommand(String, SqlConnection, SqlTransaction, SqlCommandColumnEncryptionSetting)

지정된 명령 텍스트, 연결, 트랜잭션 및 암호화 설정을 사용하여 SqlCommand 클래스의 새 인스턴스를 초기화합니다.

속성

CanRaiseEvents

구성 요소가 이벤트를 발생시킬 수 있는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 Component)
ColumnEncryptionSetting

이 명령에 대한 열 암호화 설정을 가져오거나 설정합니다.

CommandText

데이터 소스에서 실행할 Transact-SQL 문, 테이블 이름 또는 저장 프로시저를 가져오거나 설정합니다.

CommandTimeout

명령 실행을 종료하고 오류를 생성하기 전 대기 시간(초 단위)을 가져오거나 설정합니다.

CommandType

CommandText 속성이 해석될 방법을 나타내는 값을 가져오거나 설정합니다.

Connection

SqlCommand의 이 인스턴스에서 사용되는 SqlConnection을 가져오거나 설정합니다.

Container

IContainer을 포함하는 Component를 가져옵니다.

(다음에서 상속됨 Component)
DbConnection

DbConnection에서 사용하는 DbCommand을 가져오거나 설정합니다.

(다음에서 상속됨 DbCommand)
DbParameterCollection

DbParameter 개체의 컬렉션을 가져옵니다.

(다음에서 상속됨 DbCommand)
DbTransaction

DbCommand 개체를 실행할 DbTransaction을 가져오거나 설정합니다.

(다음에서 상속됨 DbCommand)
DesignMode

Component가 현재 디자인 모드인지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 Component)
DesignTimeVisible

명령 개체를 Windows Form 디자이너 컨트롤에서 표시할지를 나타내는 값을 가져오거나 설정합니다.

Events

Component에 연결된 이벤트 처리기의 목록을 가져옵니다.

(다음에서 상속됨 Component)
Notification

이 명령에 바인딩된 SqlNotificationRequest 개체를 지정하는 값을 가져오거나 설정합니다.

NotificationAutoEnlist

애플리케이션에서 일반적인 SqlDependency 개체의 쿼리 알림을 자동으로 받을지를 나타내는 값을 가져오거나 설정합니다.

Parameters

SqlParameterCollection를 가져옵니다.

Site

ComponentISite를 가져오거나 설정합니다.

(다음에서 상속됨 Component)
Transaction

SqlTransaction가 실행되는 SqlCommand을 가져오거나 설정합니다.

UpdatedRowSource

DbDataAdapterUpdate 메서드에 의해 사용될 때 명령 결과가 DataRow에 적용되는 방법을 가져오거나 설정합니다.

메서드

BeginExecuteNonQuery()

SqlCommand가 설명하는 저장 프로시저 또는 Transact-SQL 문의 비동기 실행을 시작합니다.

BeginExecuteNonQuery(AsyncCallback, Object)

콜백 프로시저와 상태 정보가 주어진 상태에서 이 SqlCommand에서 설명한 Transact-SQL 문이나 저장 프로시저의 비동기 실행을 시작합니다.

BeginExecuteReader()

SqlCommand에서 설명하는 Transact-SQL 문이나 저장 프로시저의 비동기 실행을 시작하고 서버에서 하나 이상의 결과 집합을 검색합니다.

BeginExecuteReader(AsyncCallback, Object)

콜백 프로시저와 상태 정보가 주어진 상태에서 이 SqlCommand에서 설명한 Transact-SQL 문이나 저장 프로시저의 비동기 실행을 시작하고 서버에서 하나 이상의 결과 집합을 검색합니다.

BeginExecuteReader(AsyncCallback, Object, CommandBehavior)

콜백 프로시저와 상태 정보가 주어진 상태에서 이 SqlCommand에서 설명하는 Transact-SQL 문이나 저장 프로시저의 비동기 실행을 시작하고 CommandBehavior 값 중 하나를 사용하여 서버에서 결과 집합을 하나 이상 검색합니다.

BeginExecuteReader(CommandBehavior)

CommandBehavior 값 중 하나를 사용하여 이 SqlCommand에서 설명한 Transact-SQL 문이나 저장 프로시저의 비동기 실행을 시작합니다.

BeginExecuteXmlReader()

SqlCommand에서 설명한 Transact-SQL 문이나 저장 프로시저의 비동기 실행을 시작하고 결과를 XmlReader 개체로 반환합니다.

BeginExecuteXmlReader(AsyncCallback, Object)

콜백 프로시저를 사용하여 이 SqlCommand에서 설명한 Transact-SQL 문이나 저장 프로시저의 비동기 실행을 시작하고 결과를 XmlReader 개체로 반환합니다.

Cancel()

SqlCommand의 실행을 취소하려고 시도합니다.

Clone()

현재 인스턴스의 복사본인 새 SqlCommand 개체를 만듭니다.

CreateDbParameter()

DbParameter 개체의 새 인스턴스를 만듭니다.

(다음에서 상속됨 DbCommand)
CreateObjRef(Type)

원격 개체와 통신하는 데 사용되는 프록시 생성에 필요한 모든 관련 정보가 들어 있는 개체를 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
CreateParameter()

SqlParameter 개체의 새 인스턴스를 만듭니다.

Dispose()

관리되지 않는 리소스의 확보, 해제 또는 다시 설정과 관련된 애플리케이션 정의 작업을 수행합니다.

(다음에서 상속됨 DbCommand)
Dispose()

Component에서 사용하는 모든 리소스를 해제합니다.

(다음에서 상속됨 Component)
Dispose(Boolean)

DbCommand에서 사용하는 관리되지 않는 리소스를 해제하고, 관리되는 리소스를 선택적으로 해제할 수 있습니다.

(다음에서 상속됨 DbCommand)
Dispose(Boolean)

Component에서 사용하는 관리되지 않는 리소스를 해제하고, 관리되는 리소스를 선택적으로 해제할 수 있습니다.

(다음에서 상속됨 Component)
DisposeAsync()

명령 개체를 비동기적으로 삭제합니다.

(다음에서 상속됨 DbCommand)
EndExecuteNonQuery(IAsyncResult)

Transact-SQL 문의 비동기 실행을 완료합니다.

EndExecuteReader(IAsyncResult)

요청된 SqlDataReader를 반환하는 Transact-SQL 문의 비동기 실행을 완료합니다.

EndExecuteXmlReader(IAsyncResult)

요청된 데이터를 XML로 반환하는 Transact-SQL 문의 비동기 실행을 완료합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
ExecuteDbDataReader(CommandBehavior)

해당 연결에 대해 명령을 실행하여 결과에 액세스하는 DbDataReader 데 사용할 수 있는 을 반환합니다.

(다음에서 상속됨 DbCommand)
ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken)

공급자는 ExecuteReader 오버로드에 기본값이 아닌 구현을 제공하도록 이 메서드를 구현해야 합니다.

기본 구현은 동기 ExecuteReader() 메서드를 호출하고, 호출 스레드를 차단하면서 완료된 작업을 반환합니다. 기본 구현은 이미 취소된 취소 토큰을 전달하는 경우 취소된 작업을 반환합니다. ExecuteReader에서 throw되는 예외는 반환된 Task Exception 속성을 통해 전달됩니다.

이 메서드는 조기에 취소할 작업을 요청하는 데 사용할 수 있는 취소 토큰을 허용합니다. 구현은 이 요청을 무시할 수 있습니다.

(다음에서 상속됨 DbCommand)
ExecuteNonQuery()

연결에 대한 Transact-SQL 문을 실행하고 영향을 받는 행의 수를 반환합니다.

ExecuteNonQueryAsync()

연결 개체에 대해 명령을 실행하여 영향을 받는 행 수를 반환하는 의 비동기 버전 ExecuteNonQuery()입니다.

CancellationToken.None을 사용하여 ExecuteNonQueryAsync(CancellationToken)를 호출합니다.

(다음에서 상속됨 DbCommand)
ExecuteNonQueryAsync(CancellationToken)

연결에 대해 Transact-SQL 문을 실행하고 영향을 받는 행 수를 반환하는 의 비동기 버전 ExecuteNonQuery()입니다. 취소 토큰은 명령 시간 제한이 경과하기 전에 작업을 취소하는 요청에 사용할 수 있습니다. 예외는 반환된 작업 개체를 통해 보고됩니다.

ExecuteNonQueryAsync(CancellationToken)

ExecuteNonQuery()의 비동기 버전입니다. 공급자는 적절한 구현을 재정의해야 합니다. 취소 토큰은 선택적으로 무시될 수 있습니다.

기본 구현은 동기 ExecuteNonQuery() 메서드를 호출하고, 호출 스레드를 차단하면서 완료된 작업을 반환합니다. 기본 구현은 이미 취소된 취소 토큰을 전달하는 경우 취소된 작업을 반환합니다. ExecuteNonQuery()에서 throw되는 예외는 반환된 Task Exception 속성을 통해 전달됩니다.

반환된 작업이 완료될 때까지 DbCommand 개체의 다른 메서드 및 속성을 호출하지 마십시오.

(다음에서 상속됨 DbCommand)
ExecuteReader()

CommandTextConnection에 보내고, SqlDataReader를 빌드합니다.

ExecuteReader(CommandBehavior)

CommandTextConnection에 보내고, CommandBehavior 값 중 하나를 사용하여 SqlDataReader를 빌드합니다.

ExecuteReaderAsync()

CommandTextConnection에 보내고 SqlDataReader를 작성하는 ExecuteReader()의 비동기 버전입니다. 예외는 반환된 작업 개체를 통해 보고됩니다.

ExecuteReaderAsync()

연결에 대해 명령을 실행하여 결과에 액세스하는 데 사용할 수 있는 을 DbDataReader 반환하는 의 비동기 버전ExecuteReader입니다.

CancellationToken.None을 사용하여 ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken)를 호출합니다.

(다음에서 상속됨 DbCommand)
ExecuteReaderAsync(CancellationToken)

CommandTextConnection에 보내고 SqlDataReader를 작성하는 ExecuteReader()의 비동기 버전입니다.

취소 토큰은 명령 시간 제한이 경과하기 전에 작업을 취소하는 요청에 사용할 수 있습니다. 예외는 반환된 작업 개체를 통해 보고됩니다.

ExecuteReaderAsync(CancellationToken)

연결에 대해 명령을 실행하여 결과에 액세스하는 데 사용할 수 있는 을 DbDataReader 반환하는 의 비동기 버전ExecuteReader입니다.

ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken)를 호출합니다.

(다음에서 상속됨 DbCommand)
ExecuteReaderAsync(CommandBehavior)

CommandTextConnection에 보내고 SqlDataReader를 작성하는 ExecuteReader(CommandBehavior)의 비동기 버전입니다. 예외는 반환된 작업 개체를 통해 보고됩니다.

ExecuteReaderAsync(CommandBehavior)

연결에 대해 명령을 실행하여 결과에 액세스하는 데 사용할 수 있는 을 DbDataReader 반환하는 의 비동기 버전ExecuteReader입니다.

ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken)를 호출합니다.

(다음에서 상속됨 DbCommand)
ExecuteReaderAsync(CommandBehavior, CancellationToken)

CommandTextConnection에 보내고 SqlDataReader를 작성하는 ExecuteReader(CommandBehavior)의 비동기 버전입니다.

취소 토큰은 명령 시간 제한이 경과하기 전에 작업을 취소하는 요청에 사용할 수 있습니다. 예외는 반환된 작업 개체를 통해 보고됩니다.

ExecuteReaderAsync(CommandBehavior, CancellationToken)

ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken)를 호출합니다.

(다음에서 상속됨 DbCommand)
ExecuteScalar()

쿼리를 실행하고 쿼리에서 반환한 결과 집합에서 첫 번째 행의 첫 번째 열을 반환합니다. 추가 열이나 행은 무시됩니다.

ExecuteScalarAsync()

명령을 실행하고 반환된 첫 번째 결과 집합에서 첫 번째 행의 첫 번째 열을 반환하는 의 비동기 버전 ExecuteScalar()입니다. 다른 모든 열, 행 및 결과 집합은 무시됩니다.

CancellationToken.None을 사용하여 ExecuteScalarAsync(CancellationToken)를 호출합니다.

(다음에서 상속됨 DbCommand)
ExecuteScalarAsync(CancellationToken)

쿼리를 비동기적으로 실행하고 쿼리에서 반환된 결과 집합의 첫 번째 행의 첫 번째 열을 반환하는 ExecuteScalar()의 비동기 버전입니다. 추가 열이나 행은 무시됩니다.

취소 토큰은 명령 시간 제한이 경과하기 전에 작업을 취소하는 요청에 사용할 수 있습니다. 예외는 반환된 작업 개체를 통해 보고됩니다.

ExecuteScalarAsync(CancellationToken)

ExecuteScalar()의 비동기 버전입니다. 공급자는 적절한 구현을 재정의해야 합니다. 취소 토큰은 선택적으로 무시될 수 있습니다.

기본 구현은 동기 ExecuteScalar() 메서드를 호출하고, 호출 스레드를 차단하면서 완료된 작업을 반환합니다. 기본 구현은 이미 취소된 취소 토큰을 전달하는 경우 취소된 작업을 반환합니다. ExecuteScalar에서 throw되는 예외는 반환된 Task Exception 속성을 통해 전달됩니다.

반환된 작업이 완료될 때까지 DbCommand 개체의 다른 메서드 및 속성을 호출하지 마십시오.

(다음에서 상속됨 DbCommand)
ExecuteXmlReader()

CommandTextConnection에 보내고, XmlReader 개체를 빌드합니다.

ExecuteXmlReaderAsync()

CommandTextConnection에 보내고 XmlReader 개체를 빌드하는 ExecuteXmlReader()의 비동기 버전입니다.

예외는 반환된 작업 개체를 통해 보고됩니다.

ExecuteXmlReaderAsync(CancellationToken)

CommandTextConnection에 보내고 XmlReader 개체를 빌드하는 ExecuteXmlReader()의 비동기 버전입니다.

취소 토큰은 명령 시간 제한이 경과하기 전에 작업을 취소하는 요청에 사용할 수 있습니다. 예외는 반환된 작업 개체를 통해 보고됩니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetLifetimeService()
사용되지 않음.

이 인스턴스의 수명 정책을 제어하는 현재의 수명 서비스 개체를 검색합니다.

(다음에서 상속됨 MarshalByRefObject)
GetService(Type)

Component 또는 해당 Container에서 제공하는 서비스를 나타내는 개체를 반환합니다.

(다음에서 상속됨 Component)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
InitializeLifetimeService()
사용되지 않음.

이 인스턴스의 수명 정책을 제어하는 수명 서비스 개체를 가져옵니다.

(다음에서 상속됨 MarshalByRefObject)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
MemberwiseClone(Boolean)

현재 MarshalByRefObject 개체의 단순 복사본을 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
Prepare()

SQL Server 인스턴스의 명령에 사용할 버전을 만듭니다.

PrepareAsync(CancellationToken)

데이터 소스에 대해 명령의 준비된(또는 컴파일된) 버전을 비동기적으로 만듭니다.

(다음에서 상속됨 DbCommand)
ResetCommandTimeout()

CommandTimeout 속성을 기본값으로 다시 설정합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
ToString()

Component의 이름이 포함된 String을 반환합니다(있는 경우). 이 메서드는 재정의할 수 없습니다.

(다음에서 상속됨 Component)

이벤트

Disposed

Dispose() 메서드를 호출하여 구성 요소를 삭제할 때 발생합니다.

(다음에서 상속됨 Component)
StatementCompleted

Transact-SQL 문의 실행이 완료될 때 발생합니다.

명시적 인터페이스 구현

ICloneable.Clone()

현재 인스턴스의 복사본인 새 SqlCommand 개체를 만듭니다.

IDbCommand.Connection

IDbCommand의 이 인스턴스에서 사용되는 IDbConnection을 가져오거나 설정합니다.

(다음에서 상속됨 DbCommand)
IDbCommand.CreateParameter()

SqlParameter 개체의 새 인스턴스를 만듭니다.

IDbCommand.CreateParameter()

IDbDataParameter 개체의 새 인스턴스를 만듭니다.

(다음에서 상속됨 DbCommand)
IDbCommand.ExecuteReader()

CommandTextConnection에 보내고, SqlDataReader를 빌드합니다.

IDbCommand.ExecuteReader()

Connection에 대해 CommandText를 실행하고 IDataReader를 빌드합니다.

(다음에서 상속됨 DbCommand)
IDbCommand.ExecuteReader(CommandBehavior)

CommandTextConnection에 보내고, CommandBehavior 값 중 하나를 사용하여 SqlDataReader를 빌드합니다.

IDbCommand.ExecuteReader(CommandBehavior)

Connection에 대해 CommandText를 실행하고 CommandBehavior 값 중 하나를 사용하여 IDataReader를 빌드합니다.

(다음에서 상속됨 DbCommand)
IDbCommand.Parameters

IDataParameterCollection를 가져옵니다.

(다음에서 상속됨 DbCommand)
IDbCommand.Transaction

DbCommand 개체를 실행할 DbTransaction을 가져오거나 설정합니다.

(다음에서 상속됨 DbCommand)

적용 대상

추가 정보