Connecting to MYSQL database error (UWP C#)

2019-09-09 22:29发布

I writing UWP app for windows 10 desktop

I trying to connect to DB on server

My code:

 using (MySqlConnection connection = new MySqlConnection("Database= milano_app2;Data Source=IP_OF_SERVER;User Id=USERNAME;Password=;SslMode=None;"))
        {
            connection.Open();


            MySqlCommand createCommand = new MySqlCommand("CREATE TABLE demotable(salary int,surname varchar(255))", connection);
            createCommand.ExecuteNonQuery();


            MySqlCommand addCommand = new MySqlCommand("INSERT INTO demotable (salary,surname) VALUES (1234,'Вейдер')", connection);
            addCommand.ExecuteNonQuery();

        }

But when I launch app i have this error enter image description here

I think problem in encoding of BD?

How I can make it UTF-8?

Thank's for help.

1条回答
甜甜的少女心
2楼-- · 2019-09-09 22:53

Add CharSet=utf8 to connection string :

"Database= milano_app2;Data Source=IP_OF_SERVER;User Id=USERNAME;Password=;SslMode=None;CharSet=utf8;"
查看更多
登录 后发表回答