VB.Net program to get the MySQL version

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

Prerequisites: Need to install MySQL server and MySQL connector.

MySQL Version Check in VB.Net

In this program, here we will connect to the MySQL database and print the version of MySQL on the console screen.

Create a database using the below MySql commands

mysql> create database mydb;
Query OK, 1 row affected (0.09 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb               |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.04 sec)

Program/Source Code:

The source code to get the MySQL version is given below. The given program is compiled and executed successfully.

VB.Net code to get the MySQL version

'VB.NET program to get MySQL version.

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=mydb"

        Dim conn As New MySqlConnection(connString)

        conn.Open()
        Console.WriteLine("MySQL version : " & conn.ServerVersion)
        conn.Close()
    End Sub
End Module

Output

MySQL version : 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 print the MySql version using the ServerVersion property on the console screen.

VB.Net Database Connectivity Programs »






Comments and Discussions!

Load comments ↻






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