Error on Insert Record

S

shapper

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,
Miguel
 
S

shapper

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,
Manishwww.ComponentOne.com

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,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top