Groups | Blog | Home
all groups > asp.net > february 2008 >

asp.net : Error on Insert Record



shapper
2/5/2008 7:01:40 PM
Hello,

I am creating a table has follows:

create table dbo.Tags
(
TagID uniqueidentifier not null
default NewID()
constraint PK_Tag primary key clustered,
TagText nvarchar(100) not null
)

I am using a LinqDataSource and a ListView to create records in this
table. I am able to delete and update records but when I insert a
record I get the error:

Violation of PRIMARY KEY constraint 'PK_Tag'. Cannot insert duplicate
key in object 'dbo.Tags'. The statement has been terminated.

In fact I am able to insert ONE record and its ID becomes:
00000000-0000-0000-0000-000000000000

So when I insert a second one, I suppose, the ID is 000... again and
this is why I get the error ...

What am I doing wrong?

Thanks,
Manish
2/6/2008 1:26:00 AM
Hi Miguel,

Please refer to the link below to insert the values in the Tags table. You
will have to specify the firsl column value as newid(), which will create a
new value for the TagID field.

http://technet.microsoft.com/en-us/library/ms190348.aspx

Regards,
Manish
www.ComponentOne.com


[quoted text, click to view]
shapper
2/6/2008 6:00:51 AM
[quoted text, click to view]

But please look at the code I posted:

TagID uniqueidentifier not null
default NewID()

In fact this works fine with an SQL Query.
But when I am using the ListView and LinqDataSource this does not
work.

Any idea?

Thanks,
AddThis Social Bookmark Button