SqlCeCommandBuilder.GetDeleteCommand 方法

获取在应用程序对 SqlCeDataAdapter 调用 Update 时对数据库执行删除操作所需要的、自动生成的 SqlCeCommand 对象。

命名空间:  System.Data.SqlServerCe
程序集:  System.Data.SqlServerCe(在 System.Data.SqlServerCe.dll 中)

语法

声明
Public Function GetDeleteCommand As SqlCeCommand
用法
Dim instance As SqlCeCommandBuilder
Dim returnValue As SqlCeCommand

returnValue = instance.GetDeleteCommand()
public SqlCeCommand GetDeleteCommand()
public:
SqlCeCommand^ GetDeleteCommand()
member GetDeleteCommand : unit -> SqlCeCommand 
public function GetDeleteCommand() : SqlCeCommand

返回值

类型:System.Data.SqlServerCe.SqlCeCommand
自动生成的、执行删除操作所需的 SqlCeCommand 对象。

注释

应用程序可以使用 GetDeleteCommand 方法来获取信息或解答疑难,原因是该方法返回要执行的 SqlCeCommand 对象。

也可以将 GetDeleteCommand 用作已修改的命令的基础。例如,可以调用 GetDeleteCommand,并修改它的某项属性,然后在 SqlCeDataAdapter 上显式设置该属性。

当首次生成 SQL 语句后,如果应用程序以任何方式更改该 SQL 语句,则必须显式调用 RefreshSchema()。否则,GetDeleteCommand 仍使用来自上一个语句的信息,而该信息可能不正确。当应用程序调用 UpdateGetDeleteCommand 时,将首次生成 SQL 语句。

示例

下面的示例演示了如何调用 SqlCeCommandBuilderGetDeleteCommand 方法。

Try
    Dim conn As New SqlCeConnection("Data Source = MyDatabase.sdf")
    conn.Open()

    Dim cmd As SqlCeCommand = conn.CreateCommand()
    cmd.CommandText = "SELECT * FROM employees"

    Dim adp As New SqlCeDataAdapter(cmd)

    Dim cb As New SqlCeCommandBuilder()
    cb.DataAdapter = adp

    MessageBox.Show(cb.GetUpdateCommand().CommandText)
    MessageBox.Show(cb.GetInsertCommand().CommandText)
    MessageBox.Show(cb.GetDeleteCommand().CommandText)

    Dim ds As New DataSet("test")
    adp.Fill(ds)

    ' Modify the contents of the DataSet
    '
    ds.Tables(0).Rows(0)("First Name") = "Joe"

    adp.Update(ds)

Catch e1 As Exception
    Console.WriteLine(e1.ToString())
End Try
try
{
    SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf");
    conn.Open();

    SqlCeCommand cmd = conn.CreateCommand();
    cmd.CommandText = "SELECT * FROM employees";

    SqlCeDataAdapter adp = new SqlCeDataAdapter(cmd);

    SqlCeCommandBuilder cb = new SqlCeCommandBuilder();
    cb.DataAdapter = adp;

    MessageBox.Show(cb.GetUpdateCommand().CommandText);
    MessageBox.Show(cb.GetInsertCommand().CommandText);
    MessageBox.Show(cb.GetDeleteCommand().CommandText);

    DataSet ds = new DataSet("test");
    adp.Fill(ds);

    // Modify the contents of the DataSet
    //
    ds.Tables[0].Rows[0]["First Name"] = "Joe";

    adp.Update(ds);

}
catch (Exception e1)
{
    Console.WriteLine(e1.ToString());
}

请参阅

参考

SqlCeCommandBuilder 类

GetDeleteCommand 重载

System.Data.SqlServerCe 命名空间