validate query before execution

  • Thread starter Thread starter Chuck Foster
  • Start date Start date
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
 
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
 
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
 
Back
Top