简体   繁体   English

C#匹配datagridview行以访问数据库

[英]C# match datagridview rows to access database

I am trying to figure out the best way to match items on a datagridview to items in an access database. 我试图找出将datagridview上的项目与Access数据库中的项目进行匹配的最佳方法。 (Think Quicken match transaction) (认为​​加快比赛交易)

I import an excel sheet into a datagridview,from there it checks the access db looks for a match - if a match is found then it reports match in a column if not unmatched is reported. 我将一个excel工作表导入到datagridview中,从那里检查access db寻找匹配项-如果找到匹配项,则如果报告不匹配项,它将在列中报告匹配项。

i have tried to count the rows on an sql query - if = 1 then match is yes, but that for some reason will goof up sometimes. 我试图计算一个sql查询的行-如果= 1,则match为yes,但是由于某些原因,有时会出错。

so i am looking for the best way to do this. 所以我正在寻找最好的方法来做到这一点。

Thanks - please let me know if you need any additional info. 谢谢-如果您需要任何其他信息,请告诉我。

There isn't a simple answer to this, and it depends on what your data looks like, and what you consider a "match" to be. 没有一个简单的答案,这取决于您的数据是什么样,以及您认为“匹配”是什么。 As a very basic answer, this is one way to attack the problem. 作为一个非常基本的答案,这是解决问题的一种方法。 How far you take it is up to you... 你能走多远取决于你...

  • Create an algorithm that takes all fields for a row and generates a "key" for it. 创建一种算法,该算法采用一行的所有字段并为其生成一个“键”。 For example if there are two fields [First], [Last] then perhaps the key would be "Bubba|Gump" 例如,如果有两个字段[First],[Last],则键可能是“ Bubba | Gump”
  • Apply that algorithm to both sets of data (the datagrid records and the access db records). 将该算法应用于两组数据(datagrid记录和access db记录)。
  • Compare the two sets of keys to determine what's identical/missing/added. 比较两组键,以确定什么相同/缺失/添加。

It's not foolproof but with some additional sophistication it'll take you surprisingly far. 它不是万无一失的,但是它还具有一些其他的复杂性,它将使您惊讶地走得更远。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM