- 在 btnSave_Click 事件中处理了 NoNullAllowedException
- 我在 SQL 2005 中有四列 DealerId、名称、地址、电话号码
- 如果我单击“保存”按钮,我会收到此错误:“DealerID”列不允许空值
错误信息图片:
public partial class frmDealerForm : Form
{
DataTable t;
DataRow r;
public frmDealerForm()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
t = kalliskaBillingDataSet.Tables["DealerDetail"];
r = t.NewRow();
r[0] = txtdealerID.Text;
r[1] = txtname.Text;
r[2] = txtaddress.Text;
r[3] = txtphoneno.Text;
//Column 'DealerID' does not allow nulls//
t.Rows.Add(r);
dealerDetailTableAdapter.Update(kalliskaBillingDataSet);
txtdealerID.Text = System.Convert.ToString(r[0]);
MessageBox.Show("Data Saved", "DealerDetail", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}