Preferred way to do "update row, or insert if it doesn't exist" using TableAdapters in dataset desig

Discussion in 'ASP .Net' started by H5N1, Apr 12, 2006.

  1. H5N1

    H5N1 Guest

    hi there

    the topic says it all.

    I have a outer join select statement in tableadapter that populates
    GridView, I want to make it updatetable, so I need to provide an update
    command for table adapter.
    the problem is that not all rows in gridview exist in database (since
    it's an outer join) so I want to UPDATE statement to insert the row if
    it doesn't exist.

    What's the best practice?

    thanks
     
    H5N1, Apr 12, 2006
    #1
    1. Advertising

  2. RE: Preferred way to do "update row, or insert if it doesn't exist" us

    The Sql "Pattern" for this would be (pseudocode)

    IF NOT EXISTS( SELECT PrimaryKey from table where primaryKey=@primarykey)
    BEGIN
    INSERT INTO TABLE ---etf
    END
    ELSE
    BEGIN
    UPDATE TABLE SET .... etc
    END

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "H5N1" wrote:

    > hi there
    >
    > the topic says it all.
    >
    > I have a outer join select statement in tableadapter that populates
    > GridView, I want to make it updatetable, so I need to provide an update
    > command for table adapter.
    > the problem is that not all rows in gridview exist in database (since
    > it's an outer join) so I want to UPDATE statement to insert the row if
    > it doesn't exist.
    >
    > What's the best practice?
    >
    > thanks
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Apr 12, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JIT

    Desig Application in ASP.NET

    JIT, Oct 4, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    461
  2. Shiperton Henethe
    Replies:
    117
    Views:
    2,155
    Andy Dingley
    Dec 22, 2004
  3. Nick Hustak
    Replies:
    2
    Views:
    6,302
    Nick Hustak
    Jun 27, 2006
  4. Sean
    Replies:
    0
    Views:
    118
  5. swalkertdci
    Replies:
    1
    Views:
    154
    swalkertdci
    Aug 23, 2006
Loading...

Share This Page