D
D
Deka0072018-05-29 19:26:06
C++ / C#
Deka007, 2018-05-29 19:26:06

Values ​​are not added to the database through the bindingsource, what should I do?

Hello. When adding data to the Person table, the following error occurs : "Unhandled exception of type 'System.Data.NoNullAllowedException' in System.Data.dll
Additional information: Column 'p_name' does not allow values ​​equal to nulls."
.
It seems that an empty value is added to the datagridview in the "p_name" field. I don't know how to fix this.

spoiler
5b0d7d5aaad82549169742.png

program screen. Textboxes are connected via bindingsource to the database, to the Person table
spoiler
5b0d7dcd86261488107985.png

My table in db:
spoiler
5b0d7eedc6d7d291258854.png

Here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CRUID_Bank
{
    public partial class AddPerson : Form
    {
        public AddPerson()
        {
            InitializeComponent();
           
        }

        private void AddPerson_Load(object sender, EventArgs e)
        {
            // TODO: данная строка кода позволяет загрузить данные в таблицу "bankDataSet.Person". При необходимости она может быть перемещена или удалена.
            this.personTableAdapter.Fill(this.bankDataSet.Person);
            personBindingSource.DataSource = this.bankDataSet.Person;
        }

        private void button_Next_Click(object sender, EventArgs e)
        {
            this.bankDataSet.Person.AddPersonRow(bankDataSet.Person.NewPersonRow());
            personBindingSource.MoveLast();
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lenny_The_Rabbit, 2018-05-31
@Deka007

Look at what you are passing to row. Most likely, when sending data to a method, you are not passing empty values.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question