Connecting MySQL to Visual Studio C#

前端 未结 1 865
深忆病人
深忆病人 2021-01-29 11:16

I\'m trying to write data access code to connect MySQL to visual studio. I have this code so far, but I do not know if it\'s correct. I\'m using my books and have commented out

相关标签:
1条回答
  • 2021-01-29 11:50

    From the MySQL website here is their example code on how to use C# to connect to a MySQL database:

    MySql.Data.MySqlClient.MySqlConnection conn;
    string myConnectionString;
    
    myConnectionString = "server=127.0.0.1;uid=root;" +
        "pwd=12345;database=test;";
    
    try
    {
        conn = new MySql.Data.MySqlClient.MySqlConnection();
        conn.ConnectionString = myConnectionString;
        conn.Open();
    }
    catch (MySql.Data.MySqlClient.MySqlException ex)
    {
        MessageBox.Show(ex.Message);
    }
    
    0 讨论(0)
提交回复
热议问题