PC Review


Reply
Thread Tools Rate Thread

debugging an sql format string

 
 
=?Utf-8?B?cmFtb25yZWQ=?=
Guest
Posts: n/a
 
      29th Dec 2004
Hi,
I am having trouble with a little piece of code that formats an SQL string.
I am not looking for folks to debug my code, what I would like to know is how
can I see the string that I've built before it is executed, so I can fix
whatever is wrong.

//snippet
....lots of code building the string

sql = String.Format(sql, values.ToArray());

....more code, data connection, sql command, etc..

The exception is being thrown right at this line (above) and I would like to
view it. If I were doing vb, I would just say msgbox sql

what is the asp.net - c# way of doing this?

Thanks.
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      29th Dec 2004
Ramonred,

The same as in VBNet however than only one ; behind it and in the right
case.
MessageBox.Show(sql);

I hope this helps?

Cor

"ramonred" <(E-Mail Removed)>

> Hi,
> I am having trouble with a little piece of code that formats an SQL
> string.
> I am not looking for folks to debug my code, what I would like to know is
> how
> can I see the string that I've built before it is executed, so I can fix
> whatever is wrong.
>
> //snippet
> ...lots of code building the string
>
> sql = String.Format(sql, values.ToArray());
>
> ...more code, data connection, sql command, etc..
>
> The exception is being thrown right at this line (above) and I would like
> to
> view it. If I were doing vb, I would just say msgbox sql
>
> what is the asp.net - c# way of doing this?
>
> Thanks.



 
Reply With Quote
 
=?UTF-8?B?TGFzc2UgVsOlZ3PDpnRoZXIgS2FybHNlbg==?=
Guest
Posts: n/a
 
      29th Dec 2004
ramonred wrote:
> Hi,
> I am having trouble with a little piece of code that formats an SQL string.
> I am not looking for folks to debug my code, what I would like to know is how
> can I see the string that I've built before it is executed, so I can fix
> whatever is wrong.
>
> //snippet
> ...lots of code building the string
>
> sql = String.Format(sql, values.ToArray());
>
> ...more code, data connection, sql command, etc..
>
> The exception is being thrown right at this line (above) and I would like to

<snip>

I assume you mean that the exception occurs on the line starting with
"sql =", which means that you cannot show it through a message box since
that statement would have to occur after the exception has been thrown.

It would help knowing which kind of exception you have, but testing the
following simple code worked:

String sql = "SELECT * FROM tablename WHERE key = {0}";
ArrayList values = new ArrayList();
values.Add(123);
sql = String.Format(sql, values.ToArray());
MessageBox.Show(sql);

I should mention that the best way to deal with sql and values like this
is using parameters, which would remove any problems you might have with
formatting the values correctly (especially datetime values), but I'll
assume you can't use parameters in this case. Just make sure you don't
set yourself up for an sql injection attack.

If the exception occurs in String.Format, make sure you got the right
number of {xxx} specifies corresponding to the entries in the values
collection, and that you haven't used invalid format specifiers.

If you still can't figure out the cause of the error, post some more
code and the exception type and message.

--
Lasse Vågsæther Karlsen
http://www.vkarlsen.no/
private.php?do=newpm&u=
PGP KeyID: 0x0270466B
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Debugging: how to see entire string var value? JoeU2004 Microsoft Excel Programming 6 13th Jul 2009 11:19 AM
String function not working while debugging. archana Microsoft C# .NET 6 7th Feb 2006 08:09 AM
Exception in String.Format "Input string was not in a correct format" The Crow Microsoft C# .NET 1 23rd Sep 2005 11:04 AM
Query string for debugging Lloyd Sheen Microsoft ASP .NET 2 6th Mar 2004 10:23 PM
connection string exception : Format of the initialization string does not conform to specification starting at index 0 Gaurav Microsoft ASP .NET 0 7th Nov 2003 10:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:49 PM.