如何在DataTable更改时更新Datagridview内容

时间:2014-10-02 00:58:11

标签: c# .net winforms performance datagridview

我想在DataTable更改时更新DataGridView(myAdapter.DeleteCommand = cmd;)。

请帮帮我。感谢

我的代码是:

1

public void DoCommand(String commandText, ActionType actionType, SqlParameter[] sqlParameter)
{
    using (SqlCommand cmd = new SqlCommand())
    {
        cmd.Connection = getConnection();
        cmd.CommandText = commandText;
        cmd.Parameters.AddRange(sqlParameter);

        if (actionType == ActionType.Insert)
            myAdapter.InsertCommand = cmd;
        else if (actionType == ActionType.Update)
            myAdapter.UpdateCommand = cmd;
        else if (actionType == ActionType.Delete)
            myAdapter.DeleteCommand = cmd;

        cmd.ExecuteNonQuery();
    }
}

2

DataTable dt;
private void frmCustomers_Load(object sender, EventArgs e)
{
    dt = obj.SelectCustomer();
    dgCustomer.DataSource = localDt;
}

3

private void btnDeleteCustomer_Click(object sender, EventArgs e)
{
obj.DoCommand("delete from tbl_customer where customer_id = 1", ActionType.Delete);
}

0 个答案:

没有答案