views:

160

answers:

1

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.

+1  A: 

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.

Jon Skeet
I supplied more information. However your post is already useful. Thank you Jon. +1
Krugar
Jon, your comment was the best you could make given the information I provided. I understand :) However you gave me enough information (I'm not familiar with all this encoding stuff) to actually find what the problem was. The wrong data being inserted was in fact the one outside my application. It was being inserted in ANSI format, when it should be UTF-8. Many thanks!
Krugar