为数据库读取操作设置正确的代码页

发布于 2024-08-15 10:12:35 字数 602 浏览 2 评论 0原文

如何更改要在如下操作中使用的代码页?

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

据我了解,我可以将方法调用包装在 String.Format(IFormatProvider, String) 内。那将是伟大的。

但是,如何构造具有特定代码页的 IFormatProvider,以便我可以从存储在与数据库文件其余部分不同的代码页中的数据库中正确读取此特定数据?

更多信息
- 数据库是SQLite数据库。
- 数据为葡萄牙语。
- 我添加到数据库的数据在我的应用程序上外部显示不正确。
- 我通过应用程序添加的数据显示正确。

我想我可以追溯到这样一个事实:我认为在通过应用程序添加数据时,我正在以 UTF-8 格式添加数据。我正在使用 System.Data.SQLite 提供程序,我可能会进一步调查如何更改此行为。无论如何,我现在想读取从外部源插入数据库的数据,这些数据不是 UTF-8 格式的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟酒忠诚 2024-08-22 10:12:35

不,String.Format(等等)都与客户端处理有关。如果您确实需要更改数据库处理文本数据的方式,我希望它成为 SQL 语句或可能是连接字符串的一部分。 (您可能需要对这些特定查询使用不同的连接。)

在 .NET 本身内,所有文本数据都只是 Unicode。老实说,我希望数据库能够知道发生了什么并自行处理差异...但是您没有给出您正在使用的数据库或如何使用数据库的详细信息表使用与其他表不同的编码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文