开发者

Trying to connect to mysql db with C#

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜