2

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. Pragma encoding shows me UTF8, so I want to save data in this encoding. 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.

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. In program I have the same problem, but other symbols on polish letters.

Can anyone help me with this?

Best Regards, Matt.

3
  • The database driver automatically converts between UTF-8 and the encoding that C#'s String uses. You do not need to do anything in your code. Commented Jan 31, 2014 at 23:07
  • Hi. Thanks for response, but without any conversion on c# it still doesn't work. I database I have ? on place, where should be polish letter.. Commented Jan 31, 2014 at 23:13
  • Hmm, maybe I have problem when I reading data from file? When I print file content I don't have polish letters too. I read it with read System.IO.File.ReadAllLines(file, Encoding.UTF8); Commented Jan 31, 2014 at 23:21

1 Answer 1

1

Solved. I read data from file - using ReadAllLines with encoding UTF8, when I change to default i have polish letters :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.