473,327 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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

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
1 2044
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
4
by: laurenq uantrell | last post by:
I am trying to determine which of three stored procedure designs are fastest in the Query Analyzer: One query is a straight SELECT query with all desired rows and a dozen (tblName.RowName =...
13
by: Gittyup | last post by:
Help please, We have a form, based on a query, that contains a listbox. The contents of the listbox are based on the results of the query. When the form is opened, the user selects an item...
1
by: John Sway | last post by:
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...
36
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
7
by: semedao | last post by:
Hi all, I view many posts about this issue , the connected property does not tell us the current status of the socket. based on couple of suggestions of msdn , and some article here , I try to...
2
by: hafner | last post by:
Hello all, I have an extremely simple query I'm running on a linked table. However, when I run it (primarily, I'm exporting to a .txt file, but the behavior persists even if I run the query), it...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.