如何使用相同的数据库和相同的程序在.NET两种不同的语言环境两种、如何使用、不同、语言

2023-09-04 03:26:19 作者:背靠背,沉默ヾ

我有一个C#程序,它使用database.I我已经在使用它的SQL Server中使用的国家。作为小数点分隔符。 现在,我想用它在使用其他国家,如小数点分隔符。

I have a C# program which uses a SQL Server database.I am already using it in a country that uses . as decimal separator. Now I want to use it in another country that uses , as decimal separator.

在C#是没有办法,我可以改变或写一些code,这样我可以使用相同的数据库和相同的程序某些应用程序级的设置?或者我必须改变我的整个code来处理这个新的小数点?

in C# is there some application level setting that I can change or write some code so that I can use the same database and the same program ? or do I have to change my entire code to handle this new decimal separator?

我不知道这是如何works.Basically我认为会有我的SQL查询的问题。 例如说,我现有的语句之一

I dont know how this works.Basically I think there would be problems in My Sql Queries. example say one of my existing statements is

insert into tblproducts(productId,Price) values('A12',24.10)

现在在新的国家就会变成

now in new country it will become

insert into tblproducts(productId,Price) values('A12',24,10)

这将引发一个错误

所以我必须改变整个code来处理这种情况?

so do I have to change whole code to handle this situation ?

感谢您

推荐答案

。 而不是写了这么:

 var query = "insert into tblproducts(productId,Price) values('" + article + "','"
    + price + ')';

使用 OleDbParameters :

 var query = "insert into tblproducts(productId,Price) values(?,?)"
 var cmd = new OleDbCommand(query, connection);
 cmd.Parameters.Add("@article", OleDbType.VarChar).Value = article;
 cmd.Parameters.Add("@price", OleDbType.Single).Value = price;

这会为你节省很多麻烦,包括本地化问题。

This will save you a lot of troubles, including localization issues.