Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. getting error code

getting error code

Scheduled Pinned Locked Moved C#
questioncsharphelpdiscussionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DownBySpj
    wrote on last edited by
    #1

    I have to change some of my logic based on the error returned by a code. I have to first try to do a simple insert in a table. If it throws a error then i will have to change the statement(update) and again try the insert. How can i do this. Sorry if i hv posted the question in the wrong discussion board. It may be a quesiton of c# also

    G 1 Reply Last reply
    0
    • D DownBySpj

      I have to change some of my logic based on the error returned by a code. I have to first try to do a simple insert in a table. If it throws a error then i will have to change the statement(update) and again try the insert. How can i do this. Sorry if i hv posted the question in the wrong discussion board. It may be a quesiton of c# also

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      I assume that you expect an error because the record already exists? Then do it the other way arond; first try the update and check how many records were updated. If the record didn't exist the number of records is zero, and you know that you have to make an insert instead. If you are using MS SQL Server, you can do this in a stored procedure:

      create procedure DoSomeSetting
      @SomeId int,
      @SomeValue somedatatype
      as

      update DaTable
      set Something = @SomeValue
      where SomeId = @SomeId

      if @@rowcount = 0 begin

      insert into DaTable (Something)
      values (@SomeValue)

      end

      --- b { font-weight: normal; }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups