【发布时间】:2017-07-05 00:29:08
【问题描述】:
我的程序中有一个表,它存储有关消息的信息,并希望检测何时向其中添加了新信息。我这样做的原因是因为我想仅在有新数据时才向用户显示新数据,而不必不断地获取所有行并显示它们。
我决定这样做的方法是使用 dataSet.HasChanged() 函数,该函数本质上应该检查数据集是否有任何新行,并且名为 DataChanged 的函数返回 dataSet.HasChanged() 值。
但是,我使用的函数总是返回 false(即使有变化)
这里是函数...
public bool DataChanged(string Table)
{
//This is the variable that will be returned
bool ChangesMade;
//Create the adapter
OleDbDataAdapter adapter = new OleDbDataAdapter(Table, connector);
//Clear the current data in the dataset
dataSet.Clear();
//Open the connection and fill the dataset
connector.Open();
adapter.Fill(dataSet, "TableData1");
connector.Close();
return ChangesMade = dataSet.HasChanges();
}
永远不会检测到出于某种原因的更改,因此即使在我向数据集添加新记录后,此函数也始终返回 false。
提供第一段中解释的功能的替代方法将非常有帮助,并且修复我当前的方法更是如此。
【问题讨论】:
标签: c# sql sql-server database oledb