Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No row was deleted/updated, error with SQL Server in C# (Winforms)

I have a table called Users with these columns

Username - Nvarchar(50).
Password - Nvarchar(50).

Now I have this data

UserName    Password
----------  ----------
adimin       123456
test         1234
abc           123 
abc           123

Now I'm trying to (manually) delete the abc users and I'm getting this error:

Error

I can add more users and update them and delete them, but I can't do anything with the abc users.. Why does it happen?

like image 678
ShmuelCohen Avatar asked Apr 14 '26 22:04

ShmuelCohen


2 Answers

You can delete the records with a delete statement rather than manually in the IDE:

delete from users
where username = 'abc'
like image 119
juergen d Avatar answered Apr 16 '26 11:04

juergen d


Visual Studio is complaining because you didn't define a Primary Key. Add, for example, an identity column and it won't complain any more (since it'll know exactly which row to delete).

Ex.: ALTER TABLE users ADD id INT IDENTITY PRIMARY KEY

like image 31
ssarabando Avatar answered Apr 16 '26 11:04

ssarabando



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!