将dataGridView中的添加/删除等修改保存至数据库 ,支持多条操作,最后一次性保存

C# dataGridView控件数据批量修改并同步到数据库 方法一:使用循环读取dataGridView中每行每列的值然后一行行写入到数据库 获取每行每列的值 代码如下: for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { for (int j = 0;j<dataGridView1.Columns.Count;j++) { Console.WriteLine(dataGridView1.Rows[i].Cells[j].Value.ToString()); } } 数据库中的 阅读详情

1、窗体级变量,准备工作

 

        MMS.Public.DbAccLibry.DbAccess myDbacc;

 

        //// <summary>
        /// 批量修改数据库交易对象
        /// </summary>
        private SqlDataAdapter myDAMult = new SqlDataAdapter();

        /// <summary>
        /// 批量修改记录集
        /// </summary>
        private DataSet myDsMult = new DataSet();
        /// <summary>
        /// 批量修改参数
        /// </summary>
        private SqlParameter myParmMult = new SqlParameter();

        /// <summary>
        /// 数据库连接交易对象
        /// </summary>
        private SqlConnection myConn;

 

        /// <summary>
        /// SQL构造对象
        /// </summary>
        ///private SqlCommandBuilder myMultCB; 如果没指定COMMAND,则需要,否则不需要,本DEMO不需要

 

2、加载填充

        /// <summary>
        /// 加载填充
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void myComBoxClient_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            myDAMult = new SqlDataAdapter(" select ta.GoodID as 商品编码, tb.Defscancode as 商品条码,tb.GoodName as 商品名称,tb.Unit as 单位,tb.spec as 规格,ta.Clientid as 客户编号,ta.SupplyPric as 供应价格,ta.UserID as  系统操作员,ta.RepDate as 报价日期,tb.RetailPric as 零售价格,tb.WholeSalePric as 批发价格,tb.MemPric as 会员价格 from Bill_GoodRepPricInfo ta,jcv_GoodBaseInfo tb where ta.GoodID=tb.GoodID and   ta.clientid= @v_clientid   ", myConn);

            myDAMult.SelectCommand.Parameters.Add("@v_clientid", SqlDbType.VarChar, 80).Value =myComBoxClient.GetSelectID() ;

            if (myDsMult != null && myDsMult.Tables.Count != 0 && myDsMult.Tables[0].Rows.Count > 0)
            {
                myDsMult.Tables.Clear();
        &nbs

使用DataGridView进行增删改查,并同步到数据库 DataGridView控件功能特别强悍,具有极高的可配置性和可扩展性。它提供有大量的属性、方法和事件,可以用来对该控件的外观和行为进行自定义。 阅读详情

相关推荐

DataGridView连接Sql数据库 功能 查询 添加 删除 修改

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data

blacop的博客 3955

DataGridView删除选中多行数据

前言: datagridview是C#中比较常用的数据显示控件,并且支持选中操作。   private void btClearup_Click(object sender, EventArgs e) { string rowFirstCell; //接收选中行数据 if (dgv.Rows.Count...

天天开心鸭! 3457

DataGridView直接更改表中数据

一定要巧妙利用DataGridView的事件private void dataview_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { /* *作用是导入数据后可以直接在有数据的表格上修改 */ ...

pengbostudio的博客 3000

dataGridView更新数据库

C#winform   dataGridView更新数据库  dataGridView更新数据库可以分2中情况: 1 dataGridView更新数据库自定义数据源更新数据库, 2  dataGridView数据源控件更新数据库。 当dataGridView控件启用了编辑、删除功能,你编辑了dataGridView中到列该dataGridView对应到dataset中到数据也会跟着更新但要

大尾巴狼专栏 1万+

C#操作Datagridview-增、删、改、查、上移、下移

1. CRUD 操作的核心基础是「全局数据源(_studentGlobalList)+ 数据绑定(DataSource)」,所有操作均基于全局数据源,最后通过重新绑定刷新表格。查:筛选全局数据源副本 → 重新绑定;增:验证 → 添加到全局数据源 → 重新绑定;改:选中验证 → 匹配全局数据源实体 → 更新属性 → 重新绑定;删:选中验证 → 确认删除 → 移除全局数据源实体 → 重新绑定。3. 数据一致性:所有操作必须同步全局数据源,避免表格展示与底层数据脱节。

kylezhao2019的博客 1859

在DataGridView中实现数据的筛选功能

1、筛选功能的核心:保留原始数据源 → LINQ 生成筛选副本 → 重新绑定刷新 DataGridView。2、关键技术:LINQ Where() 方法实现条件筛选,Contains() 实现模糊匹配,== 实现精准匹配,ToList() 完成结果集转换。3、核心注意点:始终不修改原始数据源,做好输入验证和边界处理,支持筛选重置,提升用户体验。4、扩展方向:可通过 TextChanged 事件实现实时筛选,或增加更多筛选条件(如日期范围、多值选择)满足复杂业务需求。

kylezhao2019的博客 979

一个简单的C#的ACCESS操作类

这几天一直在忙着用C#+ACCESS写一个winform应用程序,用到从ACCESS数据库查询,并且将数据返回到datagridview中。由于没有用.net开发的经验,连接ACCESS数据库花费了点精力,最后发现其实要绑定数据到datagridview中,只需把datagridview的datasource设为从数据库读出的datatable就可以了,寻着这个思路,自己写了一个ACCESS的

outer of the space 1万+

Winform连接MySQL数据库实现增删查改功能

       这个练手小项目是今年8月刚接触C#的时候做的...当时对C#还不熟,边查资料边完成的,其实有很多需要优化的地方...数据库是提前创建好的,用户名密码什么的直接写在点击连接按钮事件中了,可能未来的某一天想起来这个小项目会回来完善一下   界面   代码 using System; using System.Collections.Generic; using Sys...

Vacía的博客 1万+

Winform DataGridView七种列类型详解:从基础到实战应用

在C# Winform桌面开发中,数据展示与交互是核心需求之一。DataGridView作为.NET Framework中功能强大的表格控件,其数据绑定机制和丰富的列类型是实现高效数据呈现的基础。通过理解其内置的七种DataGridViewColumn类型,开发者可以构建出专业且交互性强的用户界面。从基础的DataGridViewTextBoxColumn文本输入,到DataGridViewButtonColumn的操作按钮、DataGridViewCheckBoxColumn的布尔值处理,再到DataGr

weixin_30314813的博客 374

C# Winform DataGridView列类型详解:从基础到高级应用实战

在C# Winform桌面应用开发中,数据展示与交互是核心需求之一。DataGridView作为Winform开发中功能强大的表格控件,其设计遵循“列类型驱动”原理,通过不同类型的列(如文本框列、下拉框列、按钮列等)实现多样化的数据呈现与用户交互。这种设计模式分离了数据与表现层,提升了开发灵活性与代码可维护性。掌握DataGridView的七种内置列类型,能够高效应对从基础数据展示到复杂业务逻辑的各类场景,例如通过DataGridViewComboBoxColumn实现规范化输入,或利用DataGridVi

weixin_30247307的博客 456

C# Winform DataGridView列类型详解:从基础到高级应用

在C# Winform桌面应用开发中,数据展示与交互是核心需求之一。其原理在于通过控件将数据模型与用户界面进行绑定,实现高效的数据呈现与编辑。DataGridView作为Winform开发中的关键控件,其技术价值在于提供了丰富、语义化的列类型,能够针对不同数据类型和交互场景进行优化,从而显著提升开发效率和用户体验。例如,DataGridViewCheckBoxColumn专为布尔值设计,自动渲染为复选框,简化了状态切换操作;DataGridViewComboBoxColumn则通过下拉列表规范输入,常用于枚

weixin_30435261的博客 483

C# DataGridView使用SqlDataAdapter.Update删除和修改数据库

首先在DataGridView添加选择框(类型为DataGridViewCheckBoxColumn)。确保数据表设置主键。 //数据库操作变量 DataSet dstSql = new DataSet(); SqlDataAdapter dadstrSql= new SqlDataAdapter(); //数据库加载函数 private void DisplayData () { str...

qq_30725967的博客 3727

C# windowForms 的DataGridView控件的使用

C# Windows Forms DataGridView 控件使用详解 DataGridView 是 Windows Forms 中用于显示和编辑表格数据的核心控件。它支持高度自定义的列类型、数据绑定、事件处理和丰富的样式配置。以下是其详细使用方法。

StevenChen的博客 660

汽车工程师必看:从CAN到Ethernet,6种车载通信协议全解析(附应用场景对比)

本文全面解析了从CAN到Ethernet的6种车载通信协议,包括CAN、LIN、MOST、FlexRay等,并对比了它们的应用场景和技术特点。文章详细介绍了各协议的演进历程、技术优势及在现代汽车中的混合网络架构设计,为汽车工程师提供了实用的协议选型指南和未来通信技术发展趋势。

weixin_28683689的博客 500

别再手动翻译PDF了!手把手教你用Zotero PDF Translate插件搞定外文文献(附最新GitHub下载链接)

本文详细介绍如何利用Zotero PDF Translate插件高效翻译外文文献,包括插件安装、配置及多引擎对比。通过划词翻译、段落翻译和全文翻译功能,显著提升科研工作效率,特别适合处理大量英文PDF文献的研究人员。

weixin_33712987的博客 784

千兆以太网的接收和crc校验

解析该以太网帧,包括统计该以太网帧长度+过滤功能(端口号对不对,是否为udp协议)+CRC校验,将解析结果存入状态fifo,一旦状态fifo开始有数,就开始开启读过程,读过程开始时,首先读状态fifo,根据从状态fifo里面读出的以太网帧长度,来读数据fifo(这样能够防止跨帧读),然后在根据状态fifo里面读出的crc校验正确标志和过滤标志,来确定是否将数据fifo读出来的数据送给下一个模块。改掉之后在抓一下,可以看到抓出来的数据完全正确,从最后开始看,除去4个crc校验的尾巴,数据是到255结束的。

weixin_45284871的博客 2747

【WRF-GHG 教程第一期】概述(Overview)

概述(Overview)

WW、forever的博客 519

2024年ERP管理系统职业技能大赛软件测试赛项-测试报告

【说明本次测试的最终测试结果总结、测试过程中遇到的重要问题以及如何解决、被测系统的质量结论、个人的收获以及团队的得失等】【说明编写本测试报告的目的和实际读者】【说明本次测试实际人员安排及主要职责】【说明本次测试使用的测试用例设计方法】【说明本次测试使用的测试方法】【针对本次测试进行Bug汇总】【针对本次测试进行用例汇总】【说明本项目的背景情况】【说明本次测试的实际。

Code is fun. 795

​​​​手把手教你玩转RT-Thread操作系统专栏--​​​​第5章 设备驱动开发:RT-Thread的设备框架​​​​5.4 I2C/SPI驱动:如何驱动外部传感器(以MPU6050为例)​

通过本节学习,掌握了基于RT-Thread设备模型的I2C/SPI驱动开发流程,包括硬件初始化、寄存器读写、设备注册及应用程序调用。I2C(Inter-Integrated Circuit)和SPI(Serial Peripheral Interface)是嵌入式系统中最常用的两种串行总线协议,广泛用于连接传感器、存储器等外设。函数通过I2C协议读取外设寄存器的数据(如MPU6050的加速度寄存器)。SPI读取需先拉低片选(CS),发送寄存器地址,再读取数据,最后拉高CS。查找I2C设备,并调用。

xiaoheshang_123的博客 129

使用Python爬取在线图书馆的图书馆藏和阅读记录

通过使用Python编写爬虫程序,我们可以从在线图书馆上获取图书馆藏和阅读记录,帮助人们更好地管理和利用图书馆资源。本文简要介绍了爬虫程序的准备工作、网页解析和数据提取、数据的保存和处理的关键步骤,并提供了一个示例代码。在实际应用中,我们需要注意遵守在线图书馆的使用规则和爬虫道德准则,确保合法、合规地进行爬取操作。以上仅为概述,实际应用的过程中可能需要根据具体需求进行适当的调整和改进。

2201_76125393的博客 747

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

上一篇: 代码动态创建ODBC数据源
下一篇: 将DataTable中满足条件的记录输入到另一个DataTable
emailqjc
博客等级 码龄21年 71粉丝 289原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值