窗户-1252不支持的编码名称。 C# [英] Windows -1252 is not supported encoding name. C#

查看:1195
本文介绍了窗户-1252不支持的编码名称。 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Windows 10的通用应用程序和ARM CPU的工作来为树莓派的应用程序。我碰到下面的错误与编码方式:

I am working with windows 10 universal App and the ARM CPU to create apps for the Raspberry Pi. I get the following error with encoding:

更多信息:'窗口1252'不是一个支持的编码名称。有关定义自定义编码的信息,请参阅Encoding.RegisterProvider方法的文档。

Additional information: 'windows-1252' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.

这是我的code。

 private async void Login(string passcode)
    {
        try
        {
            MySqlConnection conn = new MySqlConnection("Server=127.0.0.1;Port=3306;Database=database;Uid=username;Pwd=password;SslMode=None;charset=utf8");
            MySqlCommand cmd;

            conn.Open();

            cmd = new MySqlCommand("Select * from users where User = '" + passcode + "'", conn);

            MySqlDataReader dr;

            dr = cmd.ExecuteReader();

            int count = 0;

            while (dr.Read())
            {
                count += 1;
            }

            if(count == 1)
            {
                var dialog = new MessageDialog("Logged In");
                await dialog.ShowAsync();
            }
            else
            {
                var dialog = new MessageDialog("Error");
                await dialog.ShowAsync();
            }

        }
        catch (Exception ex)
        {
            if (ex is MySqlException)
            {
                MySqlException exl = (MySqlException)ex;
                var dialog = new MessageDialog(ex.Message + Environment.NewLine + exl.Number);
                await dialog.ShowAsync();
            }
            else
            {
                var dialog = new MessageDialog(ex.Message + Environment.NewLine);
                await dialog.ShowAsync();
            }

            //throw;
        }
        finally
        {
            conn.Close();
        }


    }
}

我得到的错误在这行code的

I get the error in this line of code

dr = cmd.ExecuteReader();

在我用得到它。

conn.open();

但我可以通过增加来解决它。

But I was able to solve it by adding

charset=utf8

要连接字符串。

我该如何解决这个问题?

How can I solve this error?

推荐答案

我解决了这个问题,添加

I resolved this issue adding

System.Text.EncodingProvider ppp;
ppp = System.Text.CodePagesEncodingProvider.Instance;
Encoding.RegisterProvider(ppp);

这篇关于窗户-1252不支持的编码名称。 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆