我正在创建一个需要获取字段值,添加内容然后更新该字段的应用程序。这编译并运行得很好。但是,当我在应用程序(在数据网格中)以及实际数据库中检查时,这实际上不会更新字段。
这是我更新行的地方。
//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 `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` = ?)))
我没有数据库的本地副本 - insert工作正常。 有一种更新方法(它在VS中自动完成)。 每张桌子都有PK。
未启用刷新表的选项(在编辑数据集 - >右键单击表格(在我的情况下,客户端) - > gt; configure - >高级选项)。我正在使用OLEDB连接,我猜他们不兼容?
答案 0 :(得分:0)
我将客户端绑定源拖到表单上并且已修复了!