研究Dotnetbar的Supergrid,刚生成资料,以后我会把他的功能都写上

本文介绍了一种使用C#和SqlDataAdapter进行数据更新的优化方法。通过使用DataTable的GetChanges方法来获取更改的数据行,再调用SqlDataAdapter的Update方法进行更新,可以有效地提高更新效率。这种方法减少了不必要的数据更新操作,提高了数据同步的性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 using System.Data.SqlClient;
10 
11 namespace WinFom
12 {
13     public partial class Form1 : Form
14     {
15         private DataTable DT = new DataTable();
16         private SqlDataAdapter SDA = new SqlDataAdapter();
17 
18         public Form1()
19         {
20             InitializeComponent();
21         }
22 
23         private void Form1_Load(object sender, EventArgs e)
24         {
25             SqlConnection con = new SqlConnection("Data Source=192.168.18.10;Initial Catalog=PMDATA;User ID=sa;Password=a");
26             SqlCommand cmd = new SqlCommand("Select DEPT_NO,DEPT_NM,CREATE_DATE,CREATE_BY From B_DEPT",con);
27             SDA.SelectCommand = cmd;
28             SDA.Fill(DT);
29             superGridControl1.PrimaryGrid.DataSource = DT;
30         }
31         private void GridSave(object sender, EventArgs e)
32         {
33             SqlCommandBuilder SCB = new SqlCommandBuilder(SDA);
34             SDA.Update(DT);
35         }
36 
37     }
38 }

就是这样生成的!

我也有个疑问。。听说Dataadapter的UPDATE方法会一条一条更新验证,帮助上也说要用GetChange,请问保存有更优化的方法吗?有大神指教下我这个小菜鸟吗?

 

我又问了一些高手,改良了下GridSave事件

 private void GridSave(object sender, EventArgs e)
        {
            DataTable dtchange = DT.GetChanges();
            SqlCommandBuilder SCB = new SqlCommandBuilder(SDA);
            SDA.Update(dtchange);
        }

 

转载于:https://www.cnblogs.com/season886/p/3302728.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值