表适配器更新方法不更新数据网格
本文关键字:更新 数据网 网格 数据 新方法 适配器 | 更新日期: 2023-09-27 18:13:11
我正在创建一个应用程序,它需要获取字段的值,添加一些内容,然后更新该字段。它编译和运行得很好。但是,当我在应用程序(在数据网格中)以及实际的数据库中检查字段时,这实际上并没有更新字段。
这里是我更新行的地方。
//This used to be: foreach (DataRow row in momDataSet.Clients.Rows)
//However, this doesn't seem to have any rows
foreach (DataRow row in clientsTableAdapter.GetData().Rows)
{
//all of these used to be row.ItemArray[]
if (row[6].Equals(clientID))
{
double oldAmt = Convert.ToDouble(row[8].ToString());
double newAmt = oldAmt + amt;
row[8] = newAmt;
try
{
// Tried momDataSet.AcceptChanges() here
this.clientsTableAdapter.Update(row);
//I tried momDataSet.AcceptChanges() after the update too
}
catch (Exception exc)
{
MessageBox.Show(exc.Message.ToString(), "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
这是我在应用程序中看到的数据网格。我打开一个表单来运行上面的代码,然后打开另一个表单来检查它。
public partial class frmSearch : Form
{
public frmSearch()
{
InitializeComponent();
this.clientsTableAdapter.Fill(momDataSet.Clients);
}
这是Update命令文本
UPDATE `Clients` SET `Last Name` = ?, `First Name` = ?, `E-mail Address` = ?, `Phone Number` = ?, `Rate` = ?, `Billing Type` = ?, `Outstanding balance` = ?, `Last Billed` = ?, `Notes` = ? WHERE (((? = 1 AND `Last Name` IS NULL) OR (`Last Name` = ?)) AND ((? = 1 AND `First Name` IS NULL) OR (`First Name` = ?)) AND ((? = 1 AND `E-mail Address` IS NULL) OR (`E-mail Address` = ?)) AND ((? = 1 AND `Phone Number` IS NULL) OR (`Phone Number` = ?)) AND ((? = 1 AND `Rate` IS NULL) OR (`Rate` = ?)) AND ((? = 1 AND `Billing Type` IS NULL) OR (`Billing Type` = ?)) AND (`ClientID` = ?) AND ((? = 1 AND `Outstanding balance` IS NULL) OR (`Outstanding balance` = ?)) AND ((? = 1 AND `Last Billed` IS NULL) OR (`Last Billed` = ?)))
我没有数据库的本地副本-插入工作很好。有一个更新方法(它自动完成在VS)。每张桌子都有一个PK。
未启用刷新表的选项(edit data set ->右键单击表(在我的例子中是Clients) -> configure -> advanced options)。我正在使用OLEDB连接,我猜它们不兼容?
我拖了一个客户端绑定源到表单上,它是固定的!