SqlCeParameterCollection 클래스
SqlCeCommand와 관련된 모든 매개 변수와 DataSet 열에 대한 각 매핑을 수집합니다.
상속 계층
System.Object
System.MarshalByRefObject
System.Data.Common.DbParameterCollection
System.Data.SqlServerCe.SqlCeParameterCollection
네임스페이스: System.Data.SqlServerCe
어셈블리: System.Data.SqlServerCe(System.Data.SqlServerCe.dll)
구문
‘선언
Public NotInheritable Class SqlCeParameterCollection _
Inherits DbParameterCollection
‘사용 방법
Dim instance As SqlCeParameterCollection
public sealed class SqlCeParameterCollection : DbParameterCollection
public ref class SqlCeParameterCollection sealed : public DbParameterCollection
[<SealedAttribute>]
type SqlCeParameterCollection =
class
inherit DbParameterCollection
end
public final class SqlCeParameterCollection extends DbParameterCollection
SqlCeParameterCollection 유형에서 다음 멤버를 표시합니다.
속성
이름 | 설명 | |
---|---|---|
![]() |
Count | 컬렉션에 있는 SqlCeParameter 개체의 수를 가져옵니다. (DbParameterCollection.Count을(를) 재정의함) |
![]() |
IsFixedSize | 인프라입니다. (DbParameterCollection.IsFixedSize을(를) 재정의함) |
![]() |
IsReadOnly | 인프라입니다. (DbParameterCollection.IsReadOnly을(를) 재정의함) |
![]() |
IsSynchronized | 인프라입니다. (DbParameterCollection.IsSynchronized을(를) 재정의함) |
![]() |
Item[Int32] | 지정한 인덱스에 있는 SqlCeParameter를 가져오거나 설정합니다. |
![]() |
Item[String] | 지정된 이름을 가진 SqlCeParameter를 가져오거나 설정합니다. |
![]() |
SyncRoot | 인프라입니다. (DbParameterCollection.SyncRoot을(를) 재정의함) |
맨 위로 이동
메서드
맨 위로 이동
명시적 인터페이스 구현
이름 | 설명 | |
---|---|---|
![]() ![]() |
IList.Item | (DbParameterCollection에서 상속) |
![]() ![]() |
IDataParameterCollection.Item | (DbParameterCollection에서 상속) |
맨 위로 이동
주의
컬렉션에 있는 매개 변수의 수는 명령 텍스트에 있는 매개 변수 자리 표시자의 수와 같아야 합니다. 그렇지 않으면 .NET Compact Framework Data Provider for SQL Server Compact에서 오류가 발생합니다.
예
다음 예제에서는 SqlCeDataAdapter 내에 있는 SqlCeParameterCollection 컬렉션을 통해 SqlCeParameter의 여러 인스턴스를 만듭니다. 이러한 매개 변수는 데이터 원본 내에서 데이터를 선택하는 데 사용됩니다. 그런 다음 데이터는 DataSet에 놓입니다. 이 예제에서는 DataSet과 SqlCeDataAdapter가 적절한 스키마, 명령, 연결을 사용하여 이미 만들어진 것으로 가정합니다.
Dim cmd As SqlCeCommand = Nothing
Dim adp As SqlCeDataAdapter = Nothing
Try
adp = New SqlCeDataAdapter()
Dim conn As New SqlCeConnection("Data Source = MyDatabase.sdf")
' Create the SelectCommand
'
cmd = conn.CreateCommand()
cmd.CommandText = "SELECT * FROM Orders WHERE [Ship Country] = @country AND [Ship City] = @city"
cmd.Parameters.Add("@country", SqlDbType.NVarChar, 15)
cmd.Parameters.Add("@city", SqlDbType.NVarChar, 15)
cmd.Parameters("@country").Value = "UK"
cmd.Parameters("@city").Value = "London"
adp.SelectCommand = cmd
' Create the DeleteCommand
'
cmd = conn.CreateCommand()
cmd.CommandText = "DELETE FROM Orders WHERE [Order ID] = @orderID"
Dim p As SqlCeParameter = cmd.Parameters.Add("@orderID", SqlDbType.NChar, 5, "Order ID")
p.SourceVersion = DataRowVersion.Original
adp.DeleteCommand = cmd
' Populate the dataset with the results from the SELECT statement
'
Dim ds As New DataSet()
adp.Fill(ds)
' Modify the dataset
'
MessageBox.Show("Number of rows: " & ds.Tables(0).Rows.Count)
' Delete some rows
'
ds.Tables(0).Rows(3).Delete()
ds.Tables(0).Rows(4).Delete()
' This will execute two DELETE statements
'
adp.Update(ds.Tables(0))
Catch e As Exception
MessageBox.Show(e.Message)
Finally
If Not Nothing Is adp.SelectCommand Then
adp.SelectCommand.Dispose()
End If
If Not Nothing Is adp.DeleteCommand Then
adp.DeleteCommand.Dispose()
End If
End Try
SqlCeCommand cmd = null;
SqlCeDataAdapter adp = null;
try
{
adp = new SqlCeDataAdapter();
SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf");
// Create the SelectCommand
//
cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Orders WHERE [Ship Country] = @country AND [Ship City] = @city";
cmd.Parameters.Add("@country", SqlDbType.NVarChar, 15);
cmd.Parameters.Add("@city", SqlDbType.NVarChar, 15);
cmd.Parameters["@country"].Value = "UK";
cmd.Parameters["@city"].Value = "London";
adp.SelectCommand = cmd;
// Create the DeleteCommand
//
cmd = conn.CreateCommand();
cmd.CommandText = "DELETE FROM Orders WHERE [Order ID] = @orderID";
SqlCeParameter p = cmd.Parameters.Add("@orderID", SqlDbType.NChar, 5, "Order ID");
p.SourceVersion = DataRowVersion.Original;
adp.DeleteCommand = cmd;
// Populate the dataset with the results from the SELECT statement
//
DataSet ds = new DataSet();
adp.Fill(ds);
// Modify the dataset
//
MessageBox.Show("Number of rows: " + ds.Tables[0].Rows.Count);
// Delete some rows
//
ds.Tables[0].Rows[3].Delete();
ds.Tables[0].Rows[4].Delete();
// This will execute two DELETE statements
//
adp.Update(ds.Tables[0]);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
if (null != adp.SelectCommand) adp.SelectCommand.Dispose();
if (null != adp.DeleteCommand) adp.DeleteCommand.Dispose();
}
스레드 보안
이 형식의 모든 public static(Microsoft Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인스턴스 멤버는 스레드로부터의 안전성이 보장되지 않습니다.