Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   validate query before execution (http://www.velocityreviews.com/forums/t294904-validate-query-before-execution.html)

Chuck Foster 05-24-2006 06:40 PM

validate query before execution
 
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



John Saunders 05-24-2006 10:11 PM

Re: validate query before execution
 
"Chuck Foster" <chuckdfoster@hotmail.com> wrote in message
news:uIUM4F2fGHA.4776@TK2MSFTNGP05.phx.gbl...
> 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



Will Asrari 05-24-2006 10:22 PM

Re: validate query before execution
 
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



All times are GMT. The time now is 01:07 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.