我有一个带有 3 个 Gridviews 的 Windows 窗体(见屏幕截图)。其中一个 gridviews 在一个空单元格中获得一个新值,另外两个分别获得一个新行。单击保存按钮时,我想更新添加了值的表并将新行插入到其他两个表中。我很难找出正确的代码。现在我有:
private void buttonSave_Click(object sender, EventArgs e)
{
DataTable table1 = alereDataSet.Tables["immaster"];
DataTable table2 = uPCDataSet.Tables["UPC"];
DataTable table3 = hangtagDataSet.Tables["upccode"];
DialogResult dr = MessageBox.Show("Are you sure you want to commit the values to the databases?", "Message", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
try
{
immasterTableAdapter.Update(table1.Select(null, null, DataViewRowState.CurrentRows));
upccodeTableAdapter.Update(table3.Select(null, null, DataViewRowState.Added));
uPCTableAdapter.Update(table2.Select(null, null, DataViewRowState.Added));
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
但是当我点击保存时没有任何反应。我有一种感觉,这是因为我的表格更新方法。三个表中的两个是 VFP 表,第三个是 SQL 表。我需要帮助的是弄清楚更新命令。这两个 VFP 表不会自动创建 Update 方法,SQL 表的代码是:
UPDATE UPC
SET UPCBarcode = @UPCBarcode, UPCNumber = @UPCNumber, ItemNumber = @ItemNumber, Itemdescrip = @Itemdescrip
WHERE (UPCBarcode = @Original_UPCBarcode) AND (@IsNull_UPCNumber = 1) AND (UPCNumber IS NULL) AND (@IsNull_ItemNumber = 1) AND (ItemNumber IS NULL) AND (@IsNull_Itemdescrip = 1) AND (Itemdescrip IS NULL) OR (UPCBarcode = @Original_UPCBarcode) AND (UPCNumber = @Original_UPCNumber) AND (@IsNull_ItemNumber = 1) AND (ItemNumber IS NULL) AND
(@IsNull_Itemdescrip = 1) AND (Itemdescrip IS NULL) OR
(UPCBarcode = @Original_UPCBarcode) AND (@IsNull_UPCNumber = 1) AND (UPCNumber IS NULL) AND (ItemNumber = @Original_ItemNumber) AND
(@IsNull_Itemdescrip = 1) AND (Itemdescrip IS NULL) OR
(UPCBarcode = @Original_UPCBarcode) AND (UPCNumber = @Original_UPCNumber) AND (ItemNumber = @Original_ItemNumber) AND
(@IsNull_Itemdescrip = 1) AND (Itemdescrip IS NULL) OR
(UPCBarcode = @Original_UPCBarcode) AND (@IsNull_UPCNumber = 1) AND (UPCNumber IS NULL) AND (@IsNull_ItemNumber = 1) AND
(ItemNumber IS NULL) AND (Itemdescrip = @Original_Itemdescrip) OR
(UPCBarcode = @Original_UPCBarcode) AND (UPCNumber = @Original_UPCNumber) AND (@IsNull_ItemNumber = 1) AND (ItemNumber IS NULL) AND
(Itemdescrip = @Original_Itemdescrip) OR
(UPCBarcode = @Original_UPCBarcode) AND (@IsNull_UPCNumber = 1) AND (UPCNumber IS NULL) AND (ItemNumber = @Original_ItemNumber) AND
(Itemdescrip = @Original_Itemdescrip) OR
(UPCBarcode = @Original_UPCBarcode) AND (UPCNumber = @Original_UPCNumber) AND (ItemNumber = @Original_ItemNumber) AND
(Itemdescrip = @Original_Itemdescrip)
不知道我还应该发布什么。请询问您认为可能相关的更多代码。