How do I track in which line the error exactly occurs ?
-
-
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.
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 -
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.
-
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.
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.
-
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, 2008Thank 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. :)
-
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. :)
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