How To Use MySQL Database Stored Procedure In VbNet
In This VB.Net Tutorial We Will See How To Call A Stored Procedure From MySQL DataBase To Insert Data In Visual Basic.Net Programming Language And Visual Studio Editor.
Project Source Code:
Imports MySql.Data.MySqlClient
Public Class Using_MySQL_Stored_PROCEDURE
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
Dim params(2) As MySqlParameter
params(0) = New MySqlParameter("FLNM", MySqlDbType.VarChar)
params(0).Value = TextBoxName.Text
params(1) = New MySqlParameter("ADRS", MySqlDbType.VarChar)
params(1).Value = TextBoxAdrs.Text
params(2) = New MySqlParameter("DT", MySqlDbType.Date)
params(2).Value = DateTimePicker1.Value
Dim cmd As New MySqlCommand()
cmd.Connection = connection
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "Insert_Data"
cmd.Parameters.AddRange(params)
connection.Open()
If cmd.ExecuteNonQuery() = 1 Then
MessageBox.Show("Inserted")
Else
MessageBox.Show("Not Inserted")
End If
connection.Close()
End Sub
End Class
///////////////OUTPUT: