限制数据表以更改文化

时间:2016-11-02 11:06:31

标签: c# datatable ado.net

我正在使用多语言项目。在我更改语言时,数据表中的数字也会发生变化。我想限制这种变化。这是我的代码

public DataSet ExportFarmers(CustomerAssignmentDataModel searchDataModel)
    {

        SqlParameter[] param = new SqlParameter[8];
        param[0] = new SqlParameter("@UserId", searchDataModel.UserId);
        param[1] = new SqlParameter("@LanguageId", searchDataModel.LanguageId);
        param[2] = new SqlParameter("@BusinessUnitIds", string.IsNullOrEmpty(searchDataModel.BusinessUnitIds) ? "0" : searchDataModel.BusinessUnitIds);
        param[3] = new SqlParameter("@ZoneIds", string.IsNullOrEmpty(searchDataModel.ZoneIds) ? "0" : searchDataModel.ZoneIds);
        param[4] = new SqlParameter("@RegionIds", string.IsNullOrEmpty(searchDataModel.RegionIds) ? "0" : searchDataModel.RegionIds);
        param[5] = new SqlParameter("@TerritoryIds", string.IsNullOrEmpty(searchDataModel.TerritoryIds) ? "0" : searchDataModel.TerritoryIds);
        param[6] = new SqlParameter("@VillageIds", searchDataModel.VillageIds == "null" ? "0" : searchDataModel.VillageIds);
        param[7] = new SqlParameter("@CustomerTypeId", searchDataModel.CustomerTypeId);

        DataSet ds = DbHelper.ExecuteSQLSPToGetDataSet("SpExportFarmers", param);

        ds.Tables[0].TableName = "Farmer";
        ds.Tables[1].TableName = "Farmer Crop";

        ds.AcceptChanges();
        return ds;
    } 

在此数据表中有一列,它根据文化更改格式。但我想限制。

1 个答案:

答案 0 :(得分:0)

您应该更改应用程序默认值CultureInfo。要更改此设置,您应该在应用程序启动时使用此行。

System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

或者,如果您想使用en-US文化信息:

System.Globalization.CultureInfo.CurrentCulture = new CultureInfo("en-US");

类似的东西:

using System.Globalization;

public class Program
{
    public static void Main(string[] args)
    {
        CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;

        //your code goes here
    }
}

有关CultureInfo的更多信息,请查看here