SqlCeParameterCollection 클래스
SqlCeCommand 와 관련된 모든 매개 변수와 DataSet 열에 대한 각 매핑을 수집합니다.
네임스페이스: System.Data.SqlServerCe
어셈블리: System.Data.SqlServerCe.dll의 System.Data.SqlServerCe
구문
‘선언
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
주의
컬렉션에 있는 매개 변수의 수는 명령 텍스트에 있는 매개 변수 자리 표시자의 수와 같아야 합니다. 그렇지 않으면 .NET Compact Framework Data Provider for SQL Server Compact 3.5에서 오류가 발생합니다.
예제
다음 예제에서는 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();
}
상속 계층 구조
System. . :: . .Object
System. . :: . .MarshalByRefObject
System.Data.Common. . :: . .DbParameterCollection
System.Data.SqlServerCe..::..SqlCeParameterCollection
스레드로부터의 안전성
Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.