VB.Net program to get the Mysql version using the 'Select' statement

Here, we are going to learn how to get the Mysql version using the 'Select' statement in VB.Net?
Submitted by Nidhi, on February 09, 2021 [Last updated : March 08, 2023]

Prerequisites: Need to install MySQL server and MySQL connector.

VB.Net – MySQL Version using 'Select' Statement

In this program, here we will connect to the MySQL database and get the MySql version using the "Select" command.

Program/Source Code:

The source code to get the Mysql version using the "Select" statement is given below. The given program is compiled and executed successfully.

VB.Net code to get the Mysql version using the 'Select' statement

'VB.NET program to get MySql version 
using Select statement.

Imports MySql.Data.MySqlClient

Module Module1
    Sub Main()
        Dim connString As String
        Dim MySqlVersion 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 cmd As New MySqlCommand("Select VERSION()", conn)

        MySqlVersion = cmd.ExecuteScalar().ToString()

        Console.WriteLine("MySql Version is: " & MySqlVersion)
        conn.Close()
    End Sub
End Module

Output

MySql Version is: 8.0.22
Press any key to continue . . .

Explanation

In the above program, we imported a namespace MySql.Data.MySqlClient to establish the connection with the MySql database. Then we created a module Module1 that contains a Main() function.

The Main() function is the entry point for the program. In the Main() function, we created a connection string variable ConnString that contains the database connectivity credentials. After that we established the connection to the database using MySqlConnection class and then get the MySql version using ExecuteScalar() method of MySqlCommand class and print the result on the console screen.

VB.Net Database Connectivity Programs »





All VB.Net Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.