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. giving error message according to Sql data

giving error message according to Sql data

Scheduled Pinned Locked Moved C#
databasecomhelp
63 Posts 14 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.
  • A AspDotNetDev

    Dave Kreskowiak wrote:

    If a known condition can be tested for without relying on an exception, it's a best course of action.

    Well, I wouldn't say that's always true. Imagine if TryParse didn't exist. Would you rather Try/Catch a Parse or re-implement a version of parse that returns a bool if the string is invalid? Given the complexity of number formats (e.g., scientific notation), I would just do a Try/Catch. I guess this can be generalized as: If a known condition is exceptionally complex to test for, then just use exception handling to test if it's valid. Here's another example. I built a tool that allows the user to enter a regular expression to match against some data. Rather than validate that the regular expression is valid, I just used Try/Catch to catch exceptions thrown by invalid exceptions. I mean I COULD first check if the regular expression is valid, but it would be exceedingly complex and a waste of time when the test for validity already exists in the form of exception handling.

    [Forum Guidelines]

    D Offline
    D Offline
    Dave Kreskowiak
    wrote on last edited by
    #61

    aspdotnetdev wrote:

    Imagine if TryParse didn't exist.

    It didn't at one point. I said if it could be tested for. Obviously, you can't test for every possible failure in a Parse method. It's not practical since there are just too many possibilities. But, you can test for a single known condition, like a duplicate key.

    A guide to posting questions on CodeProject[^]
    Dave Kreskowiak

    1 Reply Last reply
    0
    • N Not Active

      Fair enough. Regardless, this is a good discussion.


      I know the language. I've read a book. - _Madmatt

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #62

      Mark Nischalke wrote:

      Regardless, this is a good discussion.

      Oh yes, in fact I wish we had more of these in the Lounge :-)

      Regards, Nish


      My technology blog: voidnish.wordpress.com

      1 Reply Last reply
      0
      • E Erdinc27

        hey guys thanks for all your replies i use MsSql 2008 express..and i tried something like that

        try
        {
        dr[j] = xnl.Item(i).ChildNodes[j].InnerText;
        }
        catch(SqlException ex)
        {
        Console.WriteLine("This Record is already exist");
        }

        but still on the screen it shows the same error which is shown in Sql screen and sometimes it gives error like object reference not set to an instance of an object in that line dr[j] = xnl.Item(i).ChildNodes[j].InnerText; what is wrong here.i read a Xml file over website and put it in a datatable is it because it cannot connect that site ?

        vemedya.com

        modified on Thursday, December 9, 2010 4:20 AM

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #63

        In this case, I'd suspect that xml.Item(i) doesn't have any child nodes, so attempting to do anything with it would cause a problem.

        I'm not a stalker, I just know things. Oh by the way, you're out of milk.

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Onyx

        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