By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

Determine whether a query returns results or not (before running it)

P: n/a
I'm writing a web-based "Query analyser" tool for our company intranet. It
allows a user to type any SQL statement in a form, and execute it over the
Web.

The SQL can be a query that returns results (e.g: SELECT * FROM members) or
it can be a T-SQL (e.g: UPDATE/DELETE/INSERT).

What I want to know is, is there any way using either SQLCommand or DataSet
or any of the other ADO.NET classes to determine what kind of query it is,
BEFORE running it?

Then, if it is a T-SQL, I can just use the ExecuteNonQuery method, and I can
hide my datagrid that would contain the results. Or if it is a "SELECT"
query, I can populate a DataSet and show the results in a grid.

Do I have to manually parse out the SQL string to determine if it is SELECT
query? Or is there a more elegant way ?

Thanks!
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
All, SELECT, DELETE, UPdate, and Insert are SQL Statements (DML) and other
statements like Drop, Create, Alter are DDL. To determine if these (which I
think is what you want to do) being written, I'd use a Regex and just make a
determination on them. You could write a few different ways, but
essentially, you could make this determination pretty easy.

I have the regex's at work to do this if you are interested. Since you are
already going this far, you may want to test for a valid from, and if you
have a Group By statement, make sure you have an aggregate function listed.
Thanks to the kick a33 Regex engine .Net gives us, it's pretty
straightforward.

Cheers,

Bill
"John Sway" <jo**@aol.com> wrote in message
news:e3*************@TK2MSFTNGP11.phx.gbl...
I'm writing a web-based "Query analyser" tool for our company intranet. It
allows a user to type any SQL statement in a form, and execute it over the
Web.

The SQL can be a query that returns results (e.g: SELECT * FROM members) or it can be a T-SQL (e.g: UPDATE/DELETE/INSERT).

What I want to know is, is there any way using either SQLCommand or DataSet or any of the other ADO.NET classes to determine what kind of query it is,
BEFORE running it?

Then, if it is a T-SQL, I can just use the ExecuteNonQuery method, and I can hide my datagrid that would contain the results. Or if it is a "SELECT"
query, I can populate a DataSet and show the results in a grid.

Do I have to manually parse out the SQL string to determine if it is SELECT query? Or is there a more elegant way ?

Thanks!

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.