C#.Net program to create a database in MySql dynamically

C#.Net program to create a database in MySql dynamically There may be many doubts when it comes to this article. We hope that after reading this article all doubts will be resolved. Let’s go to the article.

C#.Net program to create a database in MySql dynamically

C#.Net program to create a database in MySql dynamically

//C#.Net program to create a database in 
//MySql dynamically.

using MySql.Data.MySqlClient;
using System;

class Program
{
    static void Main(string[] args)
    {
        //Connection String to connect with MySQL database.
        string connString = "server=localhost;userid=root;password=root";
        MySqlConnection conn = new MySqlConnection(connString);

        conn.Open();

        MySqlCommand cmd = new MySqlCommand("create database Sample_DB", conn);
        cmd.ExecuteNonQuery();

        Console.WriteLine("Database Sample_DB created successfully");
        conn.Close();
    }
}
Database Sample_DB created successfully
Press any key to continue . . .

Final Words

C#.Net program to create a database in MySql dynamically We hope all your doubts about this topic will be resolved. See you again in the next article Thank you.

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

Share on:

Leave a Comment