Results 1 to 5 of 5

Thread: sql select statement

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    sql select statement

    Hi gurus

    I posted this question on .net forum ealizing it was the wrong forum too late, my apol.to the .net forum.

    here is my question.

    I have a select statement (select * from table) how can I check if the select statement ruturn a row,rows or nothing.

    Thanks gurus

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: sql select statement

    Please show us the code you are using to actually execute that select statement.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql select statement

    thanks for the help

    I have so far the following

    Code:
    stringcommand1=select * from table where field = variable
    
    
    osqlcommand = New SqlCommand
    osqlcommand.CommandText = stringcommand1
    osqlcommand.CommandType = CommandType.Text
    osqlcommand.Connection = osqlconn
    osqlcommand.ExecuteNonQuery()
    I need to check if my select statement return any rows as sometimes there is no value to be returned from my table


    Thanks again

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: sql select statement

    Using a ExecuteNonQuery command is normally used to update data, delete data or preform some other Data Definition Language on the database. To return data you normally use a Datareader or a Dataset. If you use a datareader you can use the .HasRows() property to see if any rows are returned from the database.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql select statement

    Thanks a bunch G.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width