SqlCeDataAdapter.DeleteCommand 속성
데이터 집합에서 레코드를 삭제하기 위한 SQL 문을 가져오거나 설정합니다.
네임스페이스: System.Data.SqlServerCe
어셈블리: System.Data.SqlServerCe(System.Data.SqlServerCe.dll)
구문
‘선언
Public Property DeleteCommand As SqlCeCommand
Get
Set
‘사용 방법
Dim instance As SqlCeDataAdapter
Dim value As SqlCeCommand
value = instance.DeleteCommand
instance.DeleteCommand = value
public SqlCeCommand DeleteCommand { get; set; }
public:
property SqlCeCommand^ DeleteCommand {
SqlCeCommand^ get ();
void set (SqlCeCommand^ value);
}
member DeleteCommand : SqlCeCommand with get, set
function get DeleteCommand () : SqlCeCommand
function set DeleteCommand (value : SqlCeCommand)
속성 값
유형: System.Data.SqlServerCe.SqlCeCommand
DataSet 의 삭제된 행에 해당하는 데이터 원본의 레코드를 삭제하기 위해 Update 작업 동안 사용되는 SqlCeCommand입니다.
주의
Update를 호출하는 동안, 이 속성이 설정되어 있지 않고 기본 키 정보가 DataSet에 있는 경우 SelectCommand 속성을 설정하고 SqlCeCommandBuilder를 사용하면 DeleteCommand가 자동으로 생성될 수 있습니다. 그러면 설정하지 않은 모든 추가 명령이 SqlCeCommandBuilder에서 생성됩니다. 이러한 생성 논리를 적용하려면 키 열에 대한 정보가 DataSet에 있어야 합니다.
DeleteCommand를 이전에 만든 SqlCeCommand에 할당하면 SqlCeCommand가 복제되지 않습니다. DeleteCommand는 이전에 만든 SqlCeCommand 개체 참조를 유지합니다.
예
다음 예제에서는 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();
}