use Below code for delete data from Sql server in asp.net :
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim RowsAffected As Integer = 0
con.Open()
Dim cq As String = String.Format("delete from UnitType where UnitTypeID= {0}", TextBox1.Text)
cmd = New SqlCommand(cq) With {.Connection = con}
RowsAffected = cmd.ExecuteNonQuery()
Label5.Text = "Successfully deleted"
FillGrid()
TextBox1.Text = ""
TextBox2.Text = ""
If con.State = ConnectionState.Open Then
con.Close()
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
No comments:
Post a Comment