Free Code Snippets in C#, Net Framework, Office 365, ASP.Net,WPF, Visual Studio, SQL Server, Antivirus free
#

SQL error: Can not insert the value NULL into column IDDetail

 

With C # applications, a database error is reported:

System.Data.SqlClient.SqlException occurred

  HResult=0x80131904

  Message=Cannot insert the value NULL into column 'IDDetail', table column does not allow nulls. INSERT fails.

 

 

 

 

Solution:

In the database table you have to set the ID field to auto-increment, so that self-incrementing integer numbers are automatically entered in the ID column.

 

Switch to auto-increment

And then under Properties-> Identity Specification the entry: (Is Identity) set to True. This also sets Identity Increment to 1 and Identity Seed to 1.

 

Typical error code in C #: When executing a SQL access

        public static void Execute_SQL(string SQL_Text)

        {

            //--------< Execute_SQL() >--------

            SqlConnection cn_connection = Get_DB_Connection();

 

            //< get Table >

            SqlCommand cmd_Command = new SqlCommand(SQL_Text, cn_connection);

            cmd_Command.ExecuteNonQuery();

            //</ get Table >

 

            //--------</ Execute_SQL() >--------

        }

 

 

After the change you can easily attach records

 

 

Error message:

System.Data.SqlClient.SqlException occurred

  HResult=0x80131904

  Message=Cannot insert the value NULL into column 'IDDetail', table 'C….MDF.dbo.tbl_Details'; column does not allow nulls. INSERT fails.

The statement has been terminated.

  Source=.Net SqlClient Data Provider

 

 

Mobile
»
SQL error: Can not insert the value NULL into column IDDetail

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de