简体   繁体   English

C#sqlite编码utf8

[英]c# sqlite encoding utf8

I have very strange problem (I have searched - this is a common problem, but I don't find any working solution). 我有一个非常奇怪的问题(我已经搜索过-这是一个常见问题,但是我找不到任何有效的解决方案)。

I'm using C# (.net 4.0) and SQLite. 我正在使用C#(.net 4.0)和SQLite。 Pragma encoding shows me UTF8, so I want to save data in this encoding. Pragma编码向我显示了UTF8,所以我想以这种编码保存数据。 I tried to use somelike this: 我试图使用这样的东西:

     private String ToUTF8(string input) {

        Encoding ecdng = Encoding.Default;

        byte[] bts = ecdng.GetBytes(input);
        ecdng = Encoding.UTF8;
        return ecdng.GetString(bts, 0, bts.Length);
        //return input;
    }

    private String FromUTF8(string input)
    {

        Encoding ecdng = Encoding.UTF8;

        byte[] bts = ecdng.GetBytes(input);
        ecdng = Encoding.Default;
        return ecdng.GetString(bts, 0, bts.Length);
        //return input;
    }

but it doesn't work. 但这不起作用。 I use ToUTF8 when I'm going to save data and FromUTF8 when I selecting data. 当我要保存数据时使用ToUTF8,而在选择数据时使用FromUTF8。

Second solution which I found is: 我发现的第二个解决方案是:

        private IDbDataParameter AddParameter(IDbCommand command, string paramName, DbType type, object value)
    {
        IDbDataParameter parameter = command.CreateParameter();
        parameter.ParameterName = paramName;
        parameter.DbType = type;
        if (value != null)
            parameter.Value = value;
        else
            parameter.Value = DBNull.Value;
        command.Parameters.Add(parameter);
        return parameter;
    }

but it doesn't work too. 但它也不起作用。

I want to store in my database polish words. 我想在我的数据库中存储波兰语单词。 When I preview data via SQLiteStudio I have strange symbols in place of polish letters. 当我通过SQLiteStudio预览数据时,我用奇怪的符号代替了波兰字母。 In program I have the same problem, but other symbols on polish letters. 在程序中,我有同样的问题,但波兰语字母上有其他符号。

Can anyone help me with this? 谁能帮我这个?

Best Regards, Matt. 最好的问候,马特。

Solved. 解决了。 I read data from file - using ReadAllLines with encoding UTF8, when I change to default i have polish letters :) 我从文件读取数据-使用ReadAllLines和UTF8编码,当我更改为默认值时,我会使用波兰字母:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM