×

VB.Net Programs

VB.Net program to drop a table from the MySql database dynamically

By Nidhi Last Updated : November 14, 2024

Prerequisites: Need to install MySQL server and MySQL connector.

VB.Net – Drop a MySQL Table

In this program, here we will connect to the MySQL database and drop a specified table from the database.

Program/Source Code:

The source code to drop a table from the MySql database dynamically is given below. The given program is compiled and executed successfully.

VB.Net code to drop a table from the MySql database dynamically

'VB.NET program to drop a table in 
'MySql database dynamically.

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 cmd As New MySqlCommand("DROP TABLE IF EXISTS employee", conn)
        cmd.ExecuteNonQuery()

        Console.WriteLine("Table employee dropped successfully")
        conn.Close()
    End Sub
End Module

Output

Table employee dropped successfully
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 MySql database using MySqlConnection class and then drop the "employee" table in the database using ExecuteNonQuery() method of MySqlCommand class and print the "Table employee dropped successfully" message on the console screen.

VB.Net Database Connectivity Programs »


Comments and Discussions!

Load comments ↻





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