Results 1 to 6 of 6

Thread: [RESOLVED] ListView Edit - SqlDataSource - All Items Update

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Resolved [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:
    1. 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?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: ListView Edit - SqlDataSource - All Items Update

    Quote Originally Posted by techgnome View Post
    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:
    1. 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?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: ListView Edit - SqlDataSource - All Items Update

    Quote Originally Posted by techgnome View Post
    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.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width