如何使用C#在Winform应用程序的DataGridview中编辑和更新 [英] How to Edit and Update in the DataGridview in winform app using c#

查看:573
本文介绍了如何使用C#在Winform应用程序的DataGridview中编辑和更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何使用c#在winform应用程序的DataGridview中编辑和更新.
如果单击更新",它也会在数据库中也被更改.

Hi,
How to Edit and Update in the DataGridview in winform app using c# .
If click Update it is Changed in the database also...

推荐答案

这将有所帮助,
http://khanrahim.wordpress .com/2010/04/10/insert-update-delete-with-datagridview-control-in-c-windows-application/ [
This will help,
http://khanrahim.wordpress.com/2010/04/10/insert-update-delete-with-datagridview-control-in-c-windows-application/[^]


如果使用dataSet,则在表适配器中查看其是否具有更新查询.
现在单击一个按钮,单击该按钮会将数据保存在数据库中.
在此按钮上单击事件使用

If You use dataSet then see whether it have query for update or not in table adapter.
Now take a button on which click the data will be saved in database.
on this button click event use

private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                yourTableAdapter.Update(yourDataSet.tablename);
                MessageBox.Show("Record Updated", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Some Error in Update", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
 
        }


数据集是所有操作的主要部分.

1.从数据库中获取数据集中的值.
2.将其与gridview绑定.将gridview设置为可编辑(因此,用户可以编辑值
他们想要的)
3.编辑后,将gridview表放入数据集.
4.最终将数据集更新到数据库.

Gridview更改为数据集.

Dataset is the main part in all your operations.

1. Fetch the values in dataset from database.
2. Bind it with gridview. Put gridview editable (so user edit values whatever
they want)
3. after editing put gridview table to dataaset.
4. finally update dataset to database.

Gridview changes to dataset.

DataTable dt = (DataTable)GridView1.DataSource; 
 Dataset ds = new dataSet;
 ds.tables[0] =  dt 



然后
将数据集更改保存到数据库 [ ^ ]



and then Save Dataset Changes to a Database[^]


这篇关于如何使用C#在Winform应用程序的DataGridview中编辑和更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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