Solved

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

Posted on 2008-10-16
4
221 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

828 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