Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-16
4
Medium Priority
?
225 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 150 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

916 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