在我的应用程序中。我正在解析excel,在excel中我正在解析一个十进制数。我使用OleDbConnection解析excell。当我在localhost上运行时,解析并转换为十进制是正确的,但是在服务器中它给出了错误的数字。它不接受<,>分隔符,因此数字会更大。
using (var conn = new OleDbConnection(connectionString))
{
conn.Open();
process = "Bağlantı açıldı";
var sheets = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT * FROM [" + sheets.Rows[0]["TABLE_NAME"].ToString() + "] ";
var adapter = new OleDbDataAdapter(cmd);
var ds = new DataSet();
adapter.Fill(ds);
conn.Close();
#region scope parse
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions()
{
IsolationLevel = System.Transactions.IsolationLevel.Serializable,
Timeout = TimeSpan.FromSeconds(24000)
}))
{
var context = new Entities2();
// düzenle
FNC_INVESTMENT_PERIOD_ACTUAL actual = new FNC_INVESTMENT_PERIOD_ACTUAL();
decimal id = 0;
List<FNC_INVESTMENT_PERIOD_ACTUAL> ActualDatas = new List<FNC_INVESTMENT_PERIOD_ACTUAL>();
foreach (DataRow element in ds.Tables[0].Rows)
{
FNC_INVESTMENT_ACTUAL_DETAIL detail = new FNC_INVESTMENT_ACTUAL_DETAIL();
string query = "select FNC_SEQ_ACTUAL_DETAIL.NEXTVAL from DUAL";
var query_result = context.Database.SqlQuery<decimal>(query);
decimal newId = query_result.First();
detail.ID = newId;
detail.REFACTUALCODE = id;
detail.DOCNO = element[1].ToString();
detail.DOCDATE = Convert.ToDateTime(element[2]);
detail.AMOUNT = Convert.ToDecimal(element[4]);
context.FNC_INVESTMENT_ACTUAL_DETAIL.Add(detail);
context.SaveChanges();
}
scope.Complete();
}
#endregion
}
1.547,07,该数字返回154707,因此在服务器中给出了大数字
我该如何解决这个问题。
预先感谢
答案 0 :(得分:0)
您必须指定文化:
Convert.ToDecimal(element [4] .Replace('。',''),新的CultureInfo(“ fr-FR”)))
请阅读此Microsoft文档以获取更多信息。
https://docs.microsoft.com/en-us/dotnet/api/system.convert.todecimal?view=netframework-4.8
答案 1 :(得分:0)