【发布时间】:2018-10-02 09:56:42
【问题描述】:
我有两个 DataTables,DataTable1 将它的一些值发送到 DataTable2。我想要做的是,如果 DataTable1 的值已经存在于 DataTable2 中,这些值将不会添加到 DataTable2。
我这里有来自 DataTable1 的值
protected void ASPxGridView1_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e)
{
if (e.ButtonID != "ADD") return;
int id = e.VisibleIndex
int DeliveredQty = Convert.ToInt32(ASPxGridView1.GetRowValues(id, "Delivered Qty"));
int InventoryID = Convert.ToInt32(ASPxGridView1.GetRowValues(id, "InventoryID"));
现在我想检查 DataTable2 的值是否存在InventoryID 行中。
这就是我的结局
int id = InventoryID;
DataTable dt = DataTable2;
DataRow[] dr = dt.Select(id.ToString());
if (dr == null)
{
"if it does not exist, values will be addded"
}
else
{
"prompt user that values exist"
}
这样做的正确方法是什么?
【问题讨论】:
-
您可以将
Contains用于第二个DataRow,但避免将整个DataTable实例存储在ViewState中,因为它会减慢页面加载速度。 -
@TimSchmelter 道歉,标题误导了,我已经修复了
-
@TetsuyaYamamoto 感谢您提出 Contains 方法的建议,但我无法理解它(谷歌根本没有帮助)。