Question

How can I change the codepage I want to use on an operation such as the one below?

string foo = (string)sqlCommand.ExecuteScalar();

As I understand I can wrap the method call inside a String.Format(IFormatProvider, String). That would be grand.

But how do I construct a IFormatProvider with a specific codepage so I can correctly read this particular data from my database that is stored in a different codepage than the rest of the database file?

More information:
- The database is a SQLite database.
- Data is in Portuguese.
- Data that I'm adding to the database externally displays incorrectly on my application.
- Data that I add through my application displays correctly.

I think I traced it down to the fact I think I'm adding data in UTF-8 format when doing it through my application. I'm using System.Data.SQLite provider and I'm may investigate further how I can change this behavior. On any case, I would like for now to read data that is being inserted into the database from external sources, which is not in UTF-8 format.

Was it helpful?

Solution

No, String.Format (etc) is all to do with the client-side processing. If you really need to alter how the database is handling textual data, I'd expect that to be part of the SQL statement or possibly the connection string. (You may need to use a different connection for these particular queries.)

Within .NET itself, all the text data will just be Unicode. To be honest, I'd hope that the database would know what was going on and handle the differences itself... but you haven't given the details of what database you're using or how one table uses a different encoding to others.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top