How To Insert Data Into MySQL Database In VbNet
In This VB.Net Tutorial We Will See How To Get Data From TextBoxes And DateTimePicker And Insert It Into MySQL DataBase Table Using MySqlCommand With Parameters In Visual Basic.Net Programming Language And Visual Studio Editor.
Project Source Code:
Imports MySql.Data.MySqlClient
Public Class Insert_Data_Into_MySQL
Dim connection As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=s_t_d")
Private Sub ButtonInsert_Click(sender As Object, e As EventArgs) Handles ButtonInsert.Click
' create a command to insert
Dim command As New MySqlCommand("INSERT INTO `student`(`FullName`, `Address`, `BirthDate`) VALUES (@fln,@adds,@brd)", connection)
' add Parameters to the command
command.Parameters.Add("@fln", MySqlDbType.VarChar).Value = TextBox1.Text
command.Parameters.Add("@adds", MySqlDbType.VarChar).Value = TextBox2.Text
command.Parameters.Add("@brd", MySqlDbType.Date).Value = DateTimePicker1.Value
connection.Open()
If command.ExecuteNonQuery() = 1 Then
MessageBox.Show("Data Inserted")
Else
MessageBox.Show("ERROR")
End If
connection.Close()
End Sub
End Class
///////////////OUTPUT:
Post A Comment:
0 comments: