VB.net Program to Insert a Record in the Mysql Database

VB.net Program to Insert a Record in the Mysql Database

VB.Net program to insert a record in the MySql database

'VB.NET program to insert a record in MySql database.

Imports MySql.Data.MySqlClient

Module Module1
    Sub Main()
        Dim connString As String
        
        'Connection String to connect with MySQL database.
        connString = "server=localhost;userid=root;password=root;database=sampledb"

        Dim conn As New MySqlConnection(connString)

        conn.Open()
        Dim InsertCommand As String

        InsertCommand = "INSERT INTO employee(eid,ename, salary) VALUES(@eid,@ename,@salary)"

        Dim cmd = New MySqlCommand(InsertCommand, conn)

        cmd.Parameters.AddWithValue("@eid", 101)
        cmd.Parameters.AddWithValue("@ename", "Amit Kumar")
        cmd.Parameters.AddWithValue("@salary", 43200)
        cmd.Prepare()

        cmd.ExecuteNonQuery()
        Console.WriteLine("Record inserted successfully")
        conn.Close()
    End Sub
End Module
Record inserted successfully
Press any key to continue . . .
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment