Solved

RE: Require suggestions for a tool to format sql strings to vb.net

Posted on 2008-10-16
4
220 Views
Last Modified: 2013-12-25
Hello All,

I'm currently devloping vb.net asp controls and in many instances have to pass an sql string to SQL 2000/ 2005. So, for example, I'll be passing this string to an SQL database:

cSQL = "INSERT INTO aTable (f1, f2, f3,f4) VALUES ('" & cWRRNo & "','" & txtNotes.Text & "','" & "" & "','" & "1')"

I'm using Visual Web Developer to develop the code.

However, as anyone knows who has had to format many of these strings, it can be long and frustrating work to correctly format the string.

Is there a software tool I can use to ease this formatting? I also use Visual Studio 2005, but can't see any utilities in there.

Any help gratefully received.
0
Comment
Question by:smileyMiles
  • 2
4 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 22736642
have you tried string.format?

cSQL = string.format("INSERT INTO aTable (f1, f2, f3,f4) VALUES ('{0}', '{1}', '', 1)",  cWRRNo, txtNotes.Text)
0
 

Author Comment

by:smileyMiles
ID: 22736880
No I didn't think to try that!

Good solution, makes life a lot easier :-)

Thanks a lot for the response.

Miles
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 22746254
And you have not added that you have to escape all apostrophe's...

How about instead doing like most professional software developers and use parametized queries or better still Stored Procedures and skip all that mess.
0
 

Author Comment

by:smileyMiles
ID: 22754892
It is a mess to format strings correctly, that is for sure. However, I don't see how using SP's can help?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question