0

I have a index table to manage database on ASP.NET MVC. When I created new a product it ran out this error. What does that mean and how to fix it ?

Cannot insert duplicate key row in object 'Production.Product' with unique index 'AK_Product_rowguid'. The duplicate key value is (00000000-0000-0000-0000-000000000000).

2 Answers 2

2

You are missing a field in your insert. You should add something like this in your insert statement:

insert
into product
( ... -- other column names
, your_column_name
)
values
( ... -- other values
, newid()
)
Sign up to request clarification or add additional context in comments.

3 Comments

The problem in ASP.NET but it's OK with your answer. Anyway, thanks a lot!
@TrungPham: I think you don't understand what is going on. The error message is a SQL Server error message, not an ASP.NET error message.
Sorry I'm wrong, it happened in SQL Server. Now I fixed it!
2

00000000-0000-0000-0000-000000000000 is uniqueidentifier in sql or system.Guid in ASP. it has not been initialized yet, so i presume u are transmitting this value from ASP. Try adding a new parameter to your query with system.guid.newguid(), or system.guid.newguid.tostring if your query uses parameters.

If you are creating t-sql script to be exectued (ex: "insert into production.product values('"+TextBox1.Text+"', newid())" or "insert into production.product values('"+TextBox1.Text+"', '"+system.guid.newguid.tostring()+"')".

You can define for the uniqueidentifier column of product table a default value newid().

5 Comments

@TrungPham: and what is your question?
I don't understand it either. Do you get some error message?
I added System.Guid.NewGuid() in Action and an error is gone. Sorry for my inconvenience.
@Andras: +1 for the helping attitude!
@Patrick: Now I understand the problem I had, please +1 for me!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.