【问题标题】:New Record from Current Rec当前记录的新记录
【发布时间】:2013-10-31 00:40:04
【问题描述】:

有时我的数据库中的新记录与以前的记录几乎相同,我想制作一个“从最后一个创建”按钮,从最后一个创建新记录(如果这不是第一个记录)

我正在尝试类似的东西: object rec = BindingSource1.Current; BindingSource1.Add(cur);

但我收到此错误:

发生“System.ArgumentException”类型的第一次机会异常 在 System.Data.dll 中

附加信息:无法将外部对象添加到此列表。

【问题讨论】:

标签: c# winforms bindingsource


【解决方案1】:

终于找到答案了!

我正在使用我的 BindingSource1 的 .AddingNew 事件

private void BindingSource1_AddingNew(object sender, AddingNewEventArgs e)
        {
  if(need_insert_from_Current)
                {
                BindingSource bs =(BindingSource)sender;
                DataRowView cur = (DataRowView)bs.Current;
                DataView dv=(DataView)bs.List;
                DataRowView drv=dv.AddNew();
                // Collect data from current rec (except from the 1st value (Id is Identity !)
                for (int i = 1; i <= dv.Table.Columns.Count-1; i++)
                {
                    drv.Row[i] = cur.Row[i];
                }
                bs.Position = bs.Count - 1;
                e.NewObject = drv;
                need_insert = true;
                need_insert_from_Current=false;
                }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-23
    • 1970-01-01
    相关资源
    最近更新 更多