开发者

Trying to connect to mysql db with C#

开发者 https://www.devze.com 2023-02-05 11:11 出处:网络
When I debug through the code just hangs on connection.Open(); I am using the connector - using MySql.Data.MySqlClient;

When I debug through the code just hangs on connection.Open();

I am using the connector - using MySql.Data.MySqlClient;

Thanks in advance.

        string strProvider = "Data Source=" + host + ";Database=" + database + ";User ID=" + user + ";Password=" + password;

        MySqlConnection connection = 开发者_StackOverflow社区new MySqlConnection(strProvider);
        MySqlCommand command = connection.CreateCommand();
        MySqlDataReader Reader;
        command.CommandText = "select * from products";
        connection.Open();
        Reader = command.ExecuteReader();
        while (Reader.Read())
        {

            string thisrow = "";
            for (int i = 0; i < Reader.FieldCount; i++)
                thisrow += Reader.GetValue(i).ToString() + ",";
            listBox1.Items.Add(thisrow);
        }
        connection.Close();


This will help http://www.connectionstrings.com/mysql

You need to change your connection string for MySQL

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号