[RESOLVED] ListView Edit - SqlDataSource - All Items Update
I'm trying to update items in my SQL database from a ListView. It works, but all entries in the database update. Not just the one I'm working on. I backed up the database prior to testing, so there's not any issues there.
This is how my SqlDataSource UPDATE command is setup:
SQL Code:
UPDATE entries SET duration = @duration, checkinDate = @checkinDate, receivedBy = @receivedBy, cosmeticDmgIn = @cosmeticDmgIn, status = N'closed'
I don't have any code setup to update the database, which is probably the issue.
When I load the ListView, select edit, type in my edits, and click "Update", all the rows in my database, for that column, are updated with that data.
I tried inserting the parameters manually, within the ItemUpdating event, but it never works.
Anyone have any ideas what I'm doing wrong?
Re: ListView Edit - SqlDataSource - All Items Update
you don't have a where clause... so you're updating all of the rows... typically you only want to update WHERE some condition is true... like a matching ID... or matching on multiple fields... or something.
-tg
Re: ListView Edit - SqlDataSource - All Items Update
Quote:
Originally Posted by
techgnome
you don't have a where clause... so you're updating all of the rows... typically you only want to update WHERE some condition is true... like a matching ID... or matching on multiple fields... or something.
-tg
Ah, yes. Of course. I'm getting too dependent on that stupid wizard :P
I'm having an issue with the WHERE statement within my UpdateCommand.
SQL Code:
UpdateCommand="UPDATE entries SET duration = @duration, checkinDate = @checkinDate, receivedBy = @receivedBy, cosmeticDmgIn = @cosmeticDmgIn, status = N'closed' WHERE platformName = @platformName, serviceTag = @serviceTag, borrowedBy = @borrowedBy">
Do you have any ideas why this isn't working?
Re: ListView Edit - SqlDataSource - All Items Update
The WHERE of an update is the same as it would be for a select... you're using comas ... does that mean AND? OR? or what?
WHERE field1=@value and field2=@Value2 or field3 = @Value3....
make sure to use () need:
WHERE field1=@value and (field2=@Value2 or field3 = @Value3)
vs
WHERE (field1=@value and field2=@Value2) or field3 = @Value3
...
-tg
Re: ListView Edit - SqlDataSource - All Items Update
Quote:
Originally Posted by
techgnome
The WHERE of an update is the same as it would be for a select... you're using comas ... does that mean AND? OR? or what?
WHERE field1=@value and field2=@Value2 or field3 = @Value3....
make sure to use () need:
WHERE field1=@value and (field2=@Value2 or field3 = @Value3)
vs
WHERE (field1=@value and field2=@Value2) or field3 = @Value3
...
-tg
I gotcha. Thanks a lot, tg.
Re: [RESOLVED] ListView Edit - SqlDataSource - All Items Update
Hello weirddemon,
A word of advice, when doing any SQL commands in your code, whether in a SqlDataSource as you are doing, or in the code behind, you need to make sure that your SQL command works directly against the database before including it in your code.
Crack open Query Analyser and make sure that your SQL is working as you expect it to. Once you know that it does, you can include it in your code. If things still aren't working, then you know that the problem must be with the code, or the configuration of the query, but not the query itself
Gary