SqlCommand 클래스

정의

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
구현

예제

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

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 일반적으로 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닫습니다. 그러나 사용자는 연결을 다시 열고 계속할 수 있습니다.

참고

이름 없음(서수라고도 함)은 SQL Server .NET Framework 데이터 공급자에서 매개 변수를 지원하지 않습니다.

생성자

SqlCommand()

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

SqlCommand(String)

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

SqlCommand(String, SqlConnection)

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

SqlCommand(String, SqlConnection, SqlTransaction)

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

SqlCommand(String, SqlConnection, SqlTransaction, SqlCommandColumnEncryptionSetting)

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

속성

ColumnEncryptionSetting

이 명령에 대한 열 암호화 설정을 가져옵니다.

CommandText

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

CommandTimeout

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

CommandType

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

Connection

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

DesignTimeVisible

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

EnableOptimizedParameterBinding

명령을 SQL Server 제출할 때 Output 및 InputOutput 방향을 사용하지 않도록 설정하여 명령 개체가 매개 변수 성능을 최적화해야 하는지 여부를 나타내는 값을 가져오거나 설정합니다.

Notification

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

NotificationAutoEnlist

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

Parameters

SqlParameterCollection 가져옵니다.

RetryLogicProvider

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

Transaction

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

UpdatedRowSource

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

메서드

BeginExecuteNonQuery()

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

BeginExecuteNonQuery(AsyncCallback, Object)

콜백 프로시저 및 상태 정보가 제공되면 이 SqlCommand 에서 설명하는 Transact-SQL 문 또는 저장 프로시저의 비동기 실행을 시작합니다.

BeginExecuteReader()

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

BeginExecuteReader(AsyncCallback, Object)

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

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 개체를 만듭니다.

CreateParameter()

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

EndExecuteNonQuery(IAsyncResult)

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

EndExecuteReader(IAsyncResult)

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

EndExecuteXmlReader(IAsyncResult)

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

ExecuteNonQuery()

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

ExecuteNonQueryAsync(CancellationToken)

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

ExecuteReader()

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

ExecuteReader(CommandBehavior)

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

ExecuteReaderAsync()

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

ExecuteReaderAsync(CancellationToken)

를 에 보내고 ConnectionCommandText 를 빌드하는 의 비동기 버전 ExecuteReader() 입니다 SqlDataReader .

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

ExecuteReaderAsync(CommandBehavior)

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

ExecuteReaderAsync(CommandBehavior, CancellationToken)

에 를 보내고 ConnectionCommandText 취소 토큰을 빌드 SqlDataReader 하는 의 비동기 버전은 ExecuteReader(CommandBehavior) 명령 시간 제한이 경과하기 전에 작업을 중단하도록 요청하는 데 사용할 수 있습니다. 예외는 반환된 작업 개체를 통해 보고됩니다.

ExecuteScalar()

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

ExecuteScalarAsync(CancellationToken)

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

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

ExecuteXmlReader()

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

ExecuteXmlReaderAsync()

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

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

ExecuteXmlReaderAsync(CancellationToken)

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

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

Prepare()

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

RegisterColumnEncryptionKeyStoreProvidersOnCommand(IDictionary<String,SqlColumnEncryptionKeyStoreProvider>)

인스턴스에 암호화 키 저장소 공급자를 SqlCommand 등록합니다. 이 함수가 호출된 경우 또는 RegisterColumnEncryptionKeyStoreProvidersOnConnection(IDictionary<String,SqlColumnEncryptionKeyStoreProvider>) 메서드를 사용하여 RegisterColumnEncryptionKeyStoreProviders(IDictionary<String,SqlColumnEncryptionKeyStoreProvider>) 등록된 공급자는 무시됩니다. 이 함수를 두 번 이상 호출할 수 있습니다. 이렇게 하면 앱이 설정된 후 사용자 지정 공급자 목록을 변경할 수 없도록 사전을 단순하게 복사합니다.

ResetCommandTimeout()

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

이벤트

StatementCompleted

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

명시적 인터페이스 구현

ICloneable.Clone()

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

적용 대상