validate query before execution

C

Chuck Foster

Does anyone know a way to check if an inline SQL statement is valid before
executing it? something like....
sql = "select * from tblOne";
sql.connection = sqlconnection1;
if (sql.IsValid())
{
//do something
}

Thanks in advance for any advice!

Chuck Foster
 
J

John Saunders

Chuck Foster said:
Does anyone know a way to check if an inline SQL statement is valid before
executing it? something like....
sql = "select * from tblOne";
sql.connection = sqlconnection1;
if (sql.IsValid())
{
//do something
}

Why not just execute the query and find out if it's valid? One of the first
things SQL Server will do is validate the syntax of the query.

Is this query coming from user input (dynamic SQL)?

John
 
W

Will Asrari

I'm confused. I can't see where or why an end-user (I'm assuming)
would be entering raw SQL statements to be processed. If you are
wanting to validate a SQL statement that you are going to write simply
use Query Analyzer to see if you get any results.

SELECT * FROM _tbl WHERE This = "that"

Then change from static to dynamic once you know that the query works.

string _sql = "SELECT * FROM _tbl WHERE This = '" + var + "';

- Will
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top