首页 > 解决方案 > Visual Studio System.Data.OleDb.OleDbException 错误

问题描述

嗨,伙计们,我目前正在 Visual Studio 中处理表单,我的一个表单称为“添加分配”。但是,每次我启动应用程序并尝试添加分配时,我都会收到一条错误消息,提示“您必须在 'ASSIGNMENT.BusinessID' 字段中输入一个值”。

我认为这是因为在我的分配访问数据表中有一个名为 BusinessID 的列。而且我的代码没有解决 BusinessID 因为我不知道如何通过我的代码自动生成它。这是在“添加作业”表单中添加作业的代码。

private void btnAddAssignment_Click(object sender, EventArgs e)
    {
        DataRow newAssignmentRow = DC.dtAssignment.NewRow();
        if (txtAssignmentDescription.Text == "")
        {
            MessageBox.Show("One or more fields is blank", "Error", MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
        }
        else
        {
            try
            {

                newAssignmentRow["AssignmentDescription"] = txtAssignmentDescription.Text;
                newAssignmentRow["AssignmentDate"] = dtpAssignmentDate.Value;
                newAssignmentRow["AssignmentFee"] = nudFee.Value;
                newAssignmentRow["Status"] = cboStatus.Text;
                DC.dtAssignment.Rows.Add(newAssignmentRow);
                MessageBox.Show("Employee added successfully", "Success");
                DC.UpdateAssignment();
                ClearFields();
            }
            catch (FormatException ex)
            {
                MessageBox.Show("Please enter a number for Fee", "Error");
            }

        }
    

这也在我的 DataController 中。我认为这应该有助于生成一个 ID,但我不确定。 代码 我将非常感谢任何帮助。非常感谢!

数据库表

标签: c#ms-access

解决方案


推荐阅读