如何处理System.Data.NoNullAllowedException

问题描述 投票:-3回答:1

我在使用toolStrip add按钮向数据库添加值时遇到一些问题。我创建了一些包含一些列的表,我定义了字段ID不能为空。

但是,如何强制用户填充此字段而不触发异常?我知道正确使用try catch,但是,我不知道在哪里插入它(在哪个事件中)

public partial class Controller: Form {
 public Controller() {
  InitializeComponent();
 }

 private void infoBindingNavigatorSaveItem_Click(object sender, EventArgs e) {
  this.Validate();
  this.infoBindingSource.EndEdit();
  this.tableAdapterManager.UpdateAll(this.assinantesDataSet1);

 }

 private void Controller_Load(object sender, EventArgs e) {
  // TODO: This line of code loads data into the 'assinantesDataSet1.Info' table. You can move, or remove it, as needed.
  this.infoTableAdapter.Fill(this.assinantesDataSet1.Info);

 }
}

UI

c# database
1个回答
0
投票

在尝试将数据插入数据库之前,请验证用户输入的数据,如果该数据无效,请通知用户。

© www.soinside.com 2019 - 2024. All rights reserved.