c# - Error while inserting data with LINQ to SQL -


When I insert data with the following code, I see an exception. What should I do?

Code:

Movie_list_DBDataContext Movie_list1 = New Movie_list_DBDataContext (); Actor Act = New Actor (); Act.Actor_Name = Acttxt.Text; Movie_list1.Actors.InsertOnSubmit (ACT); Movie_list1.SubmitChanges ();

Exception:

The primary key constraint 'PK_Actors' can not contain the duplicate key in the object 'dbo.Actors'.

I have 2 columns in my table; ID and name, and ID is the primary key.

In your .dbml the designer should ensure that id field is marked as "Auto-Generated Value" You can see properties in the properties of the field.

Generally, it is initiated according to the table in the database, if the ID is set as an auto-generated value in the database, the designer will automatically correct the "auto generated value" Set on

You can mark the desired field as "Auto-Generated Value" in the code.

ID Set the value in the generated code in the property and in the column attribute: IsDbGenerated = true


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -