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 = ""

        Try
            Using connection As New Data.SqlClient.SqlConnection(connectionString)
                Dim command As New Data.SqlClient.SqlCommand(queryString, connection)
                command.Connection.Open()
                command.ExecuteNonQuery()
                command.Connection.Close()
            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
intTotalRecordsUpdated = command.ExecuteNonQuery()

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.