Solved

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

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now