10
Answers

Question in database

Photo of Ali  Alfaraj

Ali Alfaraj

14y
2.7k
1
Greetings dear c# corner members,

I would like to create a table in my database, where all items can have duplicate values. So I understand to do that, I must not set a primary key for my table. However If I don't set a primary key for my table, I will get the following error each time I try to update my table:

Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

How can I overcome this problem?

Hope you can help

Ali

Answers (10)

0
Photo of Sam Hobbs
NA 28.7k 1.3m 14y
So you need to provide a "valid UpdateCommand". That seems clear to me. You said you don't want a primary key and I might misunderstand something but it's your data if you don't want a primary key then don't make one. Just provide a valid UpdateCommand.
0
Photo of Mayur  Gujrathi
NA 4.3k 725.7k 14y
I think you should describe your table structures how you are designing tables along  with associate table in which you are facing problem so that anyone can found can there be any way to solve it?
0
Photo of Ali  Alfaraj
NA 66 81k 14y
I don't think it is possible to set the primary and allow for duplicate values at the same time.

So, I will not set a primary key for my table and I will need to fix this error:
Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

Any suggestions????
0
Photo of Ali  Alfaraj
NA 66 81k 14y
I did set a primary key for my table. So now how to allow the item, which I assign the PK to, to have duplicate values.

Thanks,
Ali
0
Photo of Prabhakar Parihar
NA 1.3k 382.4k 14y
Hi


 Firstly u decalred prmary key on ur database atble  . . then ur duplicasy problem might be slove . .
0
Photo of Ali  Alfaraj
NA 66 81k 14y
Thanks Crich. But I'm not sure I understand what you say?

0
Photo of Ali  Alfaraj
NA 66 81k 14y
Thanks Crich. But I'm not sure I understand what you say?

0
Photo of Ali  Alfaraj
NA 66 81k 14y
Thank you Mayur for your reply.

What do you mean by "fire update query through stored procedure"


0
Photo of Crish
NA 3.7k 76.4k 14y
This Folowing Example is remove duplicate rows from a table

  1. First, run the above GROUP BY query to determine how many sets of duplicate PK values exist, and the count of duplicates for each set.
    2.Select the duplicate key values into a holding table.
SELECT col1, col2, col3=count(*) INTO holdkey FROM t1 GROUP BY col1, col2 HAVING count(*) > 1

3.SELECT DISTINCT t1.* INTO holddups FROM t1, holdkey WHERE t1.col1 = holdkey.col1 AND t1.col2 = holdkey.col2


4.
SELECT col1, col2, count(*) FROM holddups GROUP BY col1, col2

5.DELETE t1 FROM t1, holdkey WHERE t1.col1 = holdkey.col1 AND t1.col2 = holdkey.col2


6.
INSERT t1 SELECT * FROM holddups


0
Photo of Mayur  Gujrathi
NA 4.3k 725.7k 14y
I think it should have primary key without which it cant be possible but your table needs duplicate value so i think you need to fire update query through stored procedure, it might work