如何在再写之前查找记录是否存在 [英] How to find whether record exist before write again
本文介绍了如何在再写之前查找记录是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试转换文本文件,读取文本文件并加载
将它们变为变量。
现在我想看到是否记录存在再写入之前
这是正确的方式看记录退出
DataRow [] foundRows;
foundRows = this.timeattDataSet.Tables [Data]。选择(Token_no = @cToken和Date = @datetime and Time = @cTime);
Ajith
(我是c#的新手)
我的尝试:
I am trying to convert text file, read the text file and loaded
them to variables.
now I want to see whether record exist before write again
Is this correct way see record exit
DataRow[] foundRows;
foundRows = this.timeattDataSet.Tables["Data"].Select("Token_no= @cToken and Date = @datetime and Time = @cTime");
Ajith
(I am new to c#)
What I have tried:
Token1 = str.ToString().Substring(0, 9).Trim();
cToken2 = '5' + cToken1.PadLeft(5, '0');
cToken = cToken2.Substring(0, 6);
cDate = str.ToString().Substring(10, 10);
cTime = str.ToString().Substring(21, 2) + str.ToString().Substring(24, 2);
cIdno = str.ToString().Substring(30, 1);
datetime = Convert.ToDateTime(cDate);
DataRow[] foundRows;
foundRows = this.timeattDataSet.Tables["Data"].Select("Token_no= @cToken and Date = @datetime and Time = @cTime");
推荐答案
使用LINQ:
Use LINQ:
bool rowExists = timeattDataSet.Tables["Data"].AsEnumerable()
.Any(row => string.Equals(row.Field<string>("Token_no"), cToken, StringComparison.OrdinalIgnoreCase) && row.Field<DateTime>("Date") == datetime);
这篇关于如何在再写之前查找记录是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文