ExecuteNonQuery SQLCommand

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark

    #1

    ExecuteNonQuery SQLCommand

    Hi, I have a sqlCommand object that I use to execute an SQL statement.

    I thought I could use the ExecuteNonQuery to test for the number of rows
    returned by the sql command but it does not seem to work

    My code is below..

    Dim sSQL As String = "SELECT Blah FROM Table WHERE BlahID = 5"

    Dim oCOmmand As New SqlClient.SqlCo mmand(sSQL, openDatabase)

    If oCOmmand.Execut eNonQuery > 0 Then

    ' At least one row matches SQL statement

    Else

    ' no rows match the sql statement

    End If

    Help appreciated as I thought the number ExecuteNonQuery returned the number
    of rows affected by the SQL statement.

    If I run the SQL command in query analyser I get at least one row returned.

    Cheers
    Mark


  • W.G.Ryan

    #2
    Re: ExecuteNonQuery SQLCommand

    Records Affectged doesn't show SELECT results. You could either use a
    Count(*) in your query, or you could use dr = cmd.ExecuteRead er() While
    dr.Read()
    i++;


    It'd be cool if they had a feature to return rows affected in terms of
    Select, but unless you use ADO.NET Disconnected (ie a DataAdapter, DataTable
    etc) you can't do it.

    Good Luck,

    Bill
    "Mark" <mark@yahoo.com N0SPAM> wrote in message
    news:bijmn9$cs6 $1@lust.ihug.co .nz...[color=blue]
    > Hi, I have a sqlCommand object that I use to execute an SQL statement.
    >
    > I thought I could use the ExecuteNonQuery to test for the number of rows
    > returned by the sql command but it does not seem to work
    >
    > My code is below..
    >
    > Dim sSQL As String = "SELECT Blah FROM Table WHERE BlahID = 5"
    >
    > Dim oCOmmand As New SqlClient.SqlCo mmand(sSQL, openDatabase)
    >
    > If oCOmmand.Execut eNonQuery > 0 Then
    >
    > ' At least one row matches SQL statement
    >
    > Else
    >
    > ' no rows match the sql statement
    >
    > End If
    >
    > Help appreciated as I thought the number ExecuteNonQuery returned the[/color]
    number[color=blue]
    > of rows affected by the SQL statement.
    >
    > If I run the SQL command in query analyser I get at least one row[/color]
    returned.[color=blue]
    >
    > Cheers
    > Mark
    >
    >[/color]


    Comment

    • Mark

      #3
      Re: ExecuteNonQuery SQLCommand

      Cool, thanks for that! I realise that I could use the datareader object but
      was hoping that I could just do it via the ExecuteNonQuery :)
      Thanks again
      Cheers
      Mark


      Comment

      Working...