Solved

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

Posted on 2008-10-16
4
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

624 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