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

Discussion in 'ASP .Net' started by John Sway, Aug 30, 2003.

  1. John Sway

    John Sway Guest

    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!
     
    John Sway, Aug 30, 2003
    #1
    1. Advertising

  2. John Sway

    William Ryan Guest

    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" <> wrote in message
    news:e3sSm$...
    > 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!
    >
    >
     
    William Ryan, Aug 30, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Fidge
    Replies:
    1
    Views:
    412
    Patrick Steele [MVP]
    Jun 22, 2004
  2. google_java
    Replies:
    1
    Views:
    378
    Roedy Green
    Jul 8, 2003
  3. david liu
    Replies:
    0
    Views:
    150
    david liu
    Jul 17, 2003
  4. Eric Promislow
    Replies:
    5
    Views:
    118
    Lloyd Linklater
    Sep 4, 2008
  5. Samuel
    Replies:
    2
    Views:
    113
Loading...

Share This Page