如何更新现有的itemCode

时间:2018-10-16 03:29:25

标签: c# winforms

这是我的代码

bindingSource1.CurrencyManager.AddNew();
int dtCode = dsData1.Item.AsEnumerable().Where(x => x.DataCode == txtItem.Text).Count();

if (dtCode == 0)
{
     DataRowView dr = (DataRowView)bindingSource1.CurrencyManager.Current;
     dr["DataCode"] = txtItem.Text;
     dr["Quantity"] = dtQuantity+1;
}
else
{
     //insert code for update
}
bindingSource1.CurrencyManager.EndCurrentEdit();

有人可以代替它

enter image description here

我的想法是仅显示突出显示的行,并且每当要输入另一个商品代码“ axe”时,数量+1

1 个答案:

答案 0 :(得分:0)

发现此代码

DataRow rv = (from fr in dsData1.Item.AsEnumerable()
            where fr.Field<string>("DataCode") == txtItem.Text
        select fr).FirstOrDefault();

if (rv != null)
{
    rv["Quantity"] = Convert.ToDecimal(rv["Quantity"]) + 1;
}
else
{
    bindingSource1.CurrencyManager.AddNew();
    DataRowView dr = (DataRowView)bindingSource1.CurrencyManager.Current;
    dr["DataCode"] = txtItem.Text;
    dr["Quantity"] = 1;
    bindingSource1.CurrencyManager.EndCurrentEdit();
}