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

예제

다음 예제에서는 , a SqlConnection및 . SqlCommandSqlDataReader만듭니다. 이 예제에서는 데이터를 읽고 콘솔에 읽습니다. 마지막으로, 이 예제에서는 코드 블록을 종료할 때 닫 SqlDataReaderSqlConnection 습니다 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 일반적으로 INSERT, DELETE, UPDATE 및 SET 문과 같은 명령을 실행하는 이 SqlCommand명령에서 설명하는 Transact-SQL 문 또는 저장 프로시저의 비동기 실행을 시작합니다. 각 호출은 BeginExecuteNonQuery 일반적으로 별도의 스레드에서 작업을 완료하는 EndExecuteNonQuery 호출과 쌍을 이겨야 합니다.
BeginExecuteReader 이에 설명 SqlCommand 된 Transact-SQL 문 또는 저장 프로시저의 비동기 실행을 시작하고 서버에서 하나 이상의 결과 집합을 검색합니다. 각 호출은 BeginExecuteReader 일반적으로 별도의 스레드에서 작업을 완료하는 EndExecuteReader 호출과 쌍을 이겨야 합니다.
BeginExecuteXmlReader 이 설명에 설명된 Transact-SQL 문 또는 저장 프로시저 SqlCommand의 비동기 실행을 시작합니다. 각 호출은 BeginExecuteXmlReader 일반적으로 별도의 스레드에서 작업을 완료하고 개체를 EndExecuteXmlReader반환하는 호출과 쌍을 XmlReader 이겨야 합니다.
ExecuteReader 행을 반환하는 명령을 실행합니다. 성능 향상을 ExecuteReader 위해 Transact-SQL sp_executesql 시스템 저장 프로시저를 사용하여 명령을 호출합니다. 따라서 ExecuteReader Transact-SQL SET 문과 같은 명령을 실행하는 데 사용할 경우 원하는 효과가 없을 수 있습니다.
ExecuteNonQuery Transact-SQL INSERT, DELETE, UPDATE 및 SET 문과 같은 명령을 실행합니다.
ExecuteScalar 데이터베이스에서 단일 값(예: 집계 값)을 검색합니다.
ExecuteXmlReader 개체를 CommandTextConnection 보내고 빌드합니다 XmlReader .

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

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

메모

서수라고도 하는 Nameless 매개 변수는 .NET Framework Data Provider for SQL Server에서 지원되지 않습니다.

생성자

Name Description
SqlCommand()

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

SqlCommand(String, SqlConnection, SqlTransaction, SqlCommandColumnEncryptionSetting)

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

SqlCommand(String, SqlConnection, SqlTransaction)

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

SqlCommand(String, SqlConnection)

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

SqlCommand(String)

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

속성

Name Description
ColumnEncryptionSetting

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

CommandText

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

CommandTimeout

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

CommandType

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

Connection

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

DesignTimeVisible

명령 개체를 Windows Form Designer 컨트롤에 표시할지 여부를 나타내는 값을 가져오거나 설정합니다.

EnableOptimizedParameterBinding

명령을 SQL Server 제출할 때 Output 및 InputOutput 방향을 사용하지 않도록 설정하여 명령 개체가 매개 변수 성능을 최적화해야 하는지 여부를 나타내는 값을 가져오거나 설정합니다.
이 옵션은 무시되는 경우에만 사용됩니다 CommandTypeText .

Notification

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

NotificationAutoEnlist

애플리케이션이 공통 SqlDependency 개체에서 쿼리 알림을 자동으로 수신해야 하는지 여부를 나타내는 값을 가져오거나 설정합니다.

Parameters

SqlParameterCollection를 가져옵니다.

RetryLogicProvider

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

Transaction

실행되는 내의 SqlTransactionSqlCommand 값을 가져오거나 설정합니다.

UpdatedRowSource

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

메서드

Name Description
BeginExecuteNonQuery()

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

BeginExecuteNonQuery(AsyncCallback, Object)

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

BeginExecuteReader()

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

BeginExecuteReader(AsyncCallback, Object, CommandBehavior)

다음 중 하나를 사용하여 이 SqlCommand 설명된 Transact-SQL 문 또는 저장 프로시저의 비동기 실행을 시작합니다. CommandBehavior 콜백 프로시저 및 상태 정보가 제공된 경우 값을 반환하고 서버에서 하나 이상의 결과 집합을 검색합니다.

BeginExecuteReader(AsyncCallback, Object)

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

BeginExecuteReader(CommandBehavior)

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

BeginExecuteXmlReader()

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

BeginExecuteXmlReader(AsyncCallback, Object)

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

Cancel()

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

Clone()

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

CreateParameter()

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

EndExecuteNonQuery(IAsyncResult)

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

EndExecuteReader(IAsyncResult)

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

EndExecuteXmlReader(IAsyncResult)

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

ExecuteNonQuery()

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

ExecuteNonQueryAsync(CancellationToken)

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

ExecuteReader()

CommandTextConnection 보내고 빌드합니다 SqlDataReader.

ExecuteReader(CommandBehavior)

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

ExecuteReaderAsync()

를 보내고 ExecuteReader()CommandText 빌드하는 비동기 버전Connection입니다SqlDataReader. 반환된 Task 개체를 통해 예외가 보고됩니다.

ExecuteReaderAsync(CancellationToken)

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

ExecuteReaderAsync(CommandBehavior, CancellationToken)

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

ExecuteReaderAsync(CommandBehavior)

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

ExecuteScalar()

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

ExecuteScalarAsync(CancellationToken)

쿼리를 비동기적으로 실행하고 쿼리에서 반환된 결과 집합에서 첫 번째 행의 첫 번째 열을 반환하는 비동기 버전 ExecuteScalar()입니다. 추가 열 또는 행은 무시됩니다. 취소 토큰을 사용하여 명령 시간 제한이 경과하기 전에 작업을 중단하도록 요청할 수 있습니다. 반환된 Task 개체를 통해 예외가 보고됩니다.

ExecuteXmlReader()

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

ExecuteXmlReaderAsync()

개체를 보내고 ExecuteXmlReader()CommandText 빌드하는 비동기 버전Connection입니다XmlReader. 반환된 Task 개체를 통해 예외가 보고됩니다.

ExecuteXmlReaderAsync(CancellationToken)

개체를 보내고 ExecuteXmlReader()CommandText 빌드하는 비동기 버전Connection입니다XmlReader. 취소 토큰을 사용하여 명령 시간 제한이 경과하기 전에 작업을 중단하도록 요청할 수 있습니다. 반환된 Task 개체를 통해 예외가 보고됩니다.

Prepare()

SQL Server 인스턴스에서 준비된 버전의 명령을 만듭니다.

RegisterColumnEncryptionKeyStoreProvidersOnCommand(IDictionary<String,SqlColumnEncryptionKeyStoreProvider>)

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

ResetCommandTimeout()

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

이벤트

Name Description
StatementCompleted

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

명시적 인터페이스 구현

Name Description
ICloneable.Clone()

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

적용 대상