【发布时间】:2014-05-05 20:51:27
【问题描述】:
如何在绑定的ComboBox 中有一个空项目,它使用NULL 作为插入或更新的值?
使用下面的代码,我可以手动添加额外的行。 inspector_id 列是 FK 关系的主键。我必须设置inspector_id = -1,因为C# 不允许int 是null。但是,插入(或更新)失败,因为数据库中没有 inspector_id: -1。
private void ItemInfo_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'someDBDataSet.inspector' table. You can move, or remove it, as needed.
this.inspectorTableAdapter.ClearBeforeFill = false;
someDBDataSet.inspectorRow newRow = this.someDBDataSet.inspector.NewinspectorRow();
newRow.inspector_id = -1; // Since an int in C# cannot be null
newRow.fullName = "(none)";
newRow.employeeCode = "";
this.someDBDataSet.inspector.AddinspectorRow(newRow);
this.inspectorTableAdapter.Fill(this.someDBDataSet.inspector);
//this.inspectorTableAdapter.ClearBeforeFill = false;
// TODO: This line of code loads data into the 'someDBDataSet.item' table. You can move, or remove it, as needed.
this.itemTableAdapter.Fill(this.someDBDataSet.item);
}
【问题讨论】:
标签: c# .net winforms data-binding