如何从dataGridView和数据库中删除行? [英] how to delete row from dataGridView and also from Database?

查看:96
本文介绍了如何从dataGridView和数据库中删除行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我创建了一个表单,其中我添加了一个dataGridView和四个textBoxes和两个按钮(添加,删除)。

我的问题是当我选择一个在dataGridView中行,然后单击Delete按钮,它从dataGridView中删除该行,但它对数据库没有影响。

我的代码是: -

Hi,
I created a form in which I added a dataGridView and four textBoxes and Two Buttons (Add,Delete).
My problem is when i select a Row in dataGridView and then Click on Delete button it remove that row from dataGridView but it doesn''t effect on database.
My code is :-

//In form load event
DC.SelectSta("select proName as Name,proComp as Company,proQty as Qty,proUnit as Unit from orderList", "orderList");
            dataGridView1.DataSource = DC.dataSet;
            dataGridView1.DataMember = "orderList";

//delete Button click event
try
{
    DialogResult dr = MessageBox.Show("Do You want to delete the product details?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    if (dr == DialogResult.Yes)
    {
        dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
        DC.adpt.Update(DC.dataSet, "orderList");
    }
}
catch
{ }





在此先感谢....



Thanks In advance....

推荐答案

hi


你需要编写代码在if条件下从数据库中删除。
hi
you need to write code to delete from database within if condition.


在删除按钮上单击尝试从数据库中删除数据。

然后检索数据并绑定到网格。
On delete button click try to delete data from database.
Then retrieve data & bind to grid.


添加dataGridView1.databind();
add dataGridView1.databind();


这篇关于如何从dataGridView和数据库中删除行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆