我有一个Windows表单程序,它从2个表中放置ID并将它们放在另一个表中。我正在改变我从不同项目中获得的代码。我需要它来检查ID是否已经存在于另一个表中,如果没有将它们放入其中。这是我的代码。
private void btnAllocate_Click(object sender, EventArgs e)
{
try
{
if
(DM.dtEquipment.Rows[cmEquipment.Position]["Status"].ToString() == "Pending")
{
DataRow newServiceTypeEquipment = DM.dtServiceTypeEquipment.NewRow();
newServiceTypeEquipment["EquipmentID"] = dgvEquipment["EquipmentID", cmEquipment.Position].Value;
newServiceTypeEquipment["ServiceTypeID"] = dgvServiceType["ServiceTypeID", cmServiceType.Position].Value;
DM.dsGreens.Tables["ServiceTypeEquipment"].Rows.Add(newServiceTypeEquipment);
DM.UpdateServiceTypeEquipment();
}else{
MessageBox.Show("Cannot allocate treatments to paid visits.", "Error");
}
}
catch
(ConstraintException)
{
MessageBox.Show("This treatment has already been allocated to this visit.", "Error");
}
}
任何帮助都将不胜感激。
由于