I want to delete (for example) top 5 rows in my asp.net sql server database. I used the below code but it does not work. How may I get this?
Dim con As New SqlConnection(connectionString)
Using cmd = New SqlCommand()
cmd.CommandText = "DELETE From PubTb TOP 5"
cmd.Connection = con
Dim numberDeleted As Integer = cmd.ExecuteNonQuery()
Change it as per your table and Database name. Also order it if you want to
cmd.CommandText = ";WITH CTE AS ( SELECT TOP 5 * FROM PubTb ) DELETE FROM CTE"