How To Remove Data From MySQL Database Using VbNet
In This VB.Net Tutorial We Will See How To Delete The Selected Data From MySQL DataBase Table Using TextBox For The ID To Just Remove The Data With This Specific ID Using MySqlCommand With Parameters In Visual Basic.Net Programming Language And Visual Studio Editor.
Project Source Code:
Imports MySql.Data.MySqlClient
Public Class Delete_MySQL_Data
Dim connection As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=s_t_d")
Private Sub ButtonDelete_Click(sender As Object, e As EventArgs) Handles ButtonDelete.Click
Dim command As New MySqlCommand("DELETE FROM `student` WHERE `Id` = @id", connection)
command.Parameters.Add("@id", MySqlDbType.Int64).Value = TextBox1.Text
connection.Open()
Try
If command.ExecuteNonQuery() = 1 Then
MessageBox.Show("Data Deleted")
Else
MessageBox.Show("Error")
End If
Catch ex As Exception
MessageBox.Show("Something Wrong")
End Try
connection.Close()
End Sub
End Class
///////////////OUTPUT:
Post A Comment:
0 comments: