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. Visual Basic
  4. How do I track in which line the error exactly occurs ?

How do I track in which line the error exactly occurs ?

Scheduled Pinned Locked Moved Visual Basic
helpquestion
6 Posts 4 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.
  • T Offline
    T Offline
    tiagu
    wrote on last edited by
    #1

    I am adding values to a Access table (with around 25 values).   A date conversion error occurs and I do not know in which line it occurs. It is practically very tedious to go line by line.    How do I track this.   Someone please help.   Thank you in advance.

    D D C 3 Replies Last reply
    0
    • T tiagu

      I am adding values to a Access table (with around 25 values).   A date conversion error occurs and I do not know in which line it occurs. It is practically very tedious to go line by line.    How do I track this.   Someone please help.   Thank you in advance.

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

      If your running thing under the debugger, it'll stop on the exact line the problem occurs. Also, if you're using string concatenation to "build" the SQL statement, it's very easy to get an error like your describing:

      sql = "SELECT something FROM table WHERE field1 = #" & datevalue & "#"
      

      Use parameterized queries instead to have the code automatically convert the date to the appropriate format for the database engine.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      T 1 Reply Last reply
      0
      • T tiagu

        I am adding values to a Access table (with around 25 values).   A date conversion error occurs and I do not know in which line it occurs. It is practically very tedious to go line by line.    How do I track this.   Someone please help.   Thank you in advance.

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        Ideally this should not happen. Are you not doing any sort of validations?

        जय हिंद Rajdeep.Net[^] is NOT from India. Proof.[^]

        1 Reply Last reply
        0
        • T tiagu

          I am adding values to a Access table (with around 25 values).   A date conversion error occurs and I do not know in which line it occurs. It is practically very tedious to go line by line.    How do I track this.   Someone please help.   Thank you in advance.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          If you don't want to step through the debugger, do something like this: Dim sb as StringBuilder = new StringBuilder() // first line of insert sb.AppendLine("Inserted one") // second insert sb.AppendLine("Inserted two") etc Put this in a try/catch and put a breakpoint in the catch. Then, you can look at your string builder to see which line blew up. Then you can focus on that one line ( and repeat, I would not be surprised if you fix one line and then find another has the same issue, if the code does the same thing, you're likely to have repeated your bug more than once.

          Christian Graus Driven to the arms of OSX by Vista. Please read this[^] if you don't like the answer I gave to your question.

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            If your running thing under the debugger, it'll stop on the exact line the problem occurs. Also, if you're using string concatenation to "build" the SQL statement, it's very easy to get an error like your describing:

            sql = "SELECT something FROM table WHERE field1 = #" & datevalue & "#"
            

            Use parameterized queries instead to have the code automatically convert the date to the appropriate format for the database engine.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            T Offline
            T Offline
            tiagu
            wrote on last edited by
            #5

            Thank you Dave.   I was using parameterized query and it was driving me mad.   As you have instructed i used straight query like this    sql = "SELECT something FROM table WHERE field1 = #" & datevalue & "#" and solved the problem within no time. Thanks also to Rajdeep and Christian for your replies. :)

            D 1 Reply Last reply
            0
            • T tiagu

              Thank you Dave.   I was using parameterized query and it was driving me mad.   As you have instructed i used straight query like this    sql = "SELECT something FROM table WHERE field1 = #" & datevalue & "#" and solved the problem within no time. Thanks also to Rajdeep and Christian for your replies. :)

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

              Uhhh...no. I said DO NOT do that. Use the parameterized query instead.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              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