排除当前 DataTable 行的 DataAdapter SelectCommand
是否有一种干净的方法来创建 DataAdapter SelectCommand 以从数据库中选择数据表中尚未存在的行?我正在调用 DataAdapter.Fill(DataTable) 并且只想将新行插入到 DataTable 中。
Is there a clean method of creating a DataAdapter SelectCommand to select rows from the database that are not already present in the DataTable? I am calling DataAdapter.Fill(DataTable) and only want to have new rows inserted into the DataTable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将完整数据加载到新数据表中并将其与旧数据表合并:
http://msdn.microsoft.com/en- us/library/fk68ew7b%28VS.80%29.aspx
恐怕这不是您满意的答案。您的用例是什么?
You can load the complete data into a new datatable and merge it with your old one:
http://msdn.microsoft.com/en-us/library/fk68ew7b%28VS.80%29.aspx
I'm afraid thats not a satisfactory answer for you. Whats your use case for it?
如果您的数据中包含日期时间(例如 CreaetedOn)字段,您可以使用 DataReader 实现,该实现使用 SQL 查询来过滤日期,并且仅使用比当前数据集中最旧记录更新的行填充表。
DataAdapter.Fill /w DataReader
如果您具有任何类型的顺序 id,并且您将填充 Id 值大于内存数据集中最大值的行。
If your data has a datetime (eg. CreaetedOn) field in it, you could use a DataReader implementation that is using a SQL Query to filter on the date and only fill the Table with rows that are newer than the oldest record in your current dataset.
DataAdapter.Fill /w DataReader
You could use this technique also if you have any kind of sequential id, and you would fill with rows whose Id value is larger than the largest value in your in-memory dataset.