Hope I can get help. Each time I write an Update query I have a habit of forgetting to add the where clause. I have destroyed my test records many many times.

Therefore is there a way to count the number of rows that will be updated so I can add error or warning that more that one record is being updated.

Thanks & Regards

eg: of my updateclass

Private Sub updateclass(ByVal queryString As String)
        Label1.Text = ""

            Using connection As New Data.SqlClient.SqlConnection(connectionString)
                Dim command As New Data.SqlClient.SqlCommand(queryString, connection)
            End Using
        Catch b As System.Data.SqlClient.SqlException
            errorlength = InStr(b.Message, ".")
            errormessage = Microsoft.VisualBasic.Left(b.Message, errorlength)
            Label1.Text = "Error-119: " & errormessage
            Exit Sub
        End Try
    End Sub
6 Years
Discussion Span
Last Post by adrianSigamoney

Opps just re-read your post. My example will return how many records were updated; not give you that number before hand. I would suggest using stored procedures, this way there tested first and you wont forget to add anything to your string.


This is not working. I had a stored procedure running for some time on our live system. The count before differs 9 out of ten times with number of records updated. One cannot force it to update a set number of rows. However, I now store the keys in a table and update only those keys.

Thanks anyway. This can be closed.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.