当前位置:网站首页>Datatable delete row
Datatable delete row
2022-07-18 05:32:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack
First list the correct writing , If you just want to correct the mistake immediately, copy it first ,
protected void deleteDataRow(int RowID,DataTable dt)
{
for (int i = dt.Rows.Count - 1; i >= 0; i--)
{
if (Convert.ToInt32(dt.Rows[i]["RowID"]) == RowID)
dt.Rows.RemoveAt(i);
}
} /* Why hovertree.com */If you have time to learn, keep looking at the following list of possible mistakes .
1. If you just want to delete datatable A row in the , It can be used DataRow Of delete, But you must delete it and let DataTable know , So we need .AcceptChanges() Method , The reason is that this deletion is only an identification deletion , As we usually use in the database IsDelete Field .
2. You need to delete it completely datatable Of .Rows.Remove(DataRow dr) Method , Similarly, just delete a line , If you want to delete circularly, please continue to read .
3. To completely delete the cycle, you need to use .Rows.RemoveAt(int index) Method , So if you are foreach Lovers , Please change your taste here , And if you are for Of i++ Faithfulness fans I also hope you can change your mind . Let's first look at the forward writing of the above program ( FALSE , Unavailable )
for (int i = 0, j = dt.Rows.Count; i < j; i++)
{
if (Convert.ToInt32(dt.Rows[i]["RowID"]) == RowID)
dt.Rows.RemoveAt(i);
} /* Why hovertree.com */The mistake of this is datatable Of RemoveAt() It will be updated after deletion dataTable Of index, So what you want to delete index It may not be your match Convert.ToInt32(dt.Rows[i][“RowID”]) == RowID Of index 了 , Even throw exceptions , Said you visited index non-existent .
So from the DataTable Search up and delete , In this way, even if this line meets the conditions and is deleted , The above line is still unaffected .
Said so much , I don't know if you understand ? In fact, writing this kind of article now seems a little ” retarded ”, More technology , I feel more and more that my foundation is not solid enough , I hope I can urge myself by recording here , Also hope to give beginners some help .
http://hovertree.com/menu/csharp/
manipulation dataset stay DataSet in DataRow It is the basic storage location for all its data , It is mainly composed of an array of values , representative DataTable A single line . DataRow It mainly includes the following information :1、 The current value of each column in the row ,2、 The original value of each column in the row ,3、 Line status ,4、 Link between parent line and child line
Initialize a DataRow: DataTable dataTable=dataSet.Tables[0]; DataRow newRow=dataTable.NewRow(); // use dataTable Generate DataRow You can use dataTable The pattern inside dataTable.Rows.Add(newRow);
Delete row : DataTable.Rows.Remove( Row instance ); DataTable.Rows.RemoveAt( Line number ); DataRow.Delete(); // The row itself is removed
Reading and writing DataRow Value : row[“ Name ”],row[ Column number ] You can reference one of these properties DataColumn a=dataTable.Columns(“ Name ”); // You can get a column
Make batch changes to rows : BeginEdit() Start changing ,EndEdit() End the change , At the same time, write the change result to DataSet,CancelEdit(), Cancel the change for example : row.BeginEdit(); Yes row Make changes row.EndEdit();
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/120490.html Link to the original text :https://javaforall.cn
边栏推荐
- 【2022微信小程序排雷】云开发和非云开发环境下如何正确获取openid?
- xstream解析xml的时候报错AbstractReflectionConverter$UnknownFieldException
- 知识干货:基础存储服务新手体验营
- 数字座舱新时代,头部企业博泰的洞见与预判
- 【综合笔试题】难度 2/5,递归运用及前缀和优化
- Is it a transliteration of loanwords or does it have a specific meaning?
- Huawei image xmage: seek all the images in the world, and finally see the Bodhi Heart
- 送你的代码上太空,与华为云一起开发“最伟大的作品”
- ORACLE在修改主键时出现ORA-00955报错解决方法
- 剑指 Offer打卡 栈队列堆
猜你喜欢

CFA考试报名须知

Win11如何设置多任务窗口?Win11设置多任务窗口的方法

使用TIBCO Rendezvous发送hello world,实现监听和发送

Salesforce Certified Sharing and Visibility Designer (SU20)认证考试总结

全球云市场增势迅猛,数据安全进入法治化的强监管时代

xstream解析xml的时候报错AbstractReflectionConverter$UnknownFieldException

JMM memory model
![[dynamic planning] - counting DP](/img/28/254790a65bd4e4803815147fc9b7ef.png)
[dynamic planning] - counting DP

Huawei cloud stack opens its framework to the south to help ecological partners enter the cloud efficiently

Nifi cluster construction and necessary related configurations
随机推荐
曲线上点的曲率半径计算
Huawei image xmage: seek all the images in the world, and finally see the Bodhi Heart
Byzantine Generals Problem
【深度学习】YOLOv7速度精度超越其他变体,大神AB发推,网友:还得是你!|开源...
Alibaba cloud architect Ma song: high performance computing on the cloud helps gene sequencing
【多线程】 CAS 机制解析及应用( 原子类 . 自旋锁 )、解决 ABA 问题
利用 JMeter 压测上传和下载接口实战
【7.8-7.15】写作社区精彩技术博文回顾
网络安全网格概念以及特点简单普及
Use Tibco rendezvous to send Hello world to realize monitoring and sending
Typora入门:全网最全教程
About security details timing attack
华为云Stack南向开放框架,帮助生态伙伴高效入云
送你的代码上太空,与华为云一起开发“最伟大的作品”
工程监测仪器多通道振弦无线采集仪的采集数据发送方式和在线监测管理系统
堪比猎头简历整理技巧 如何快速整理简历
Salesforce运行所有测试类并获取覆盖率报告
阿里云架构师马颂:云上高性能计算助力基因测序
抢先体验! 在浏览器里写 Flutter 是一种什么体验?
Send your code into space and develop "the greatest work" with Huawei cloud