In my application. I am parsing excel and in excel I am parcing a decimal number. I use OleDbConnection for parse excell. When I run on localhost parsing and converting to decimal is correct but in server it gives wrong numbers. It doesn't accept <,> seperator so numbers gives bigger.
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 this number returns 154707 so gives big number in server
How can I solve this problem.
Thanks in advance
You have to specify the culture:
Convert.ToDecimal(element[4].Replace('.', ' '), new CultureInfo("fr-FR"));
Please read this Microsoft document for more info.
https://docs.microsoft.com/en-us/dotnet/api/system.convert.todecimal?view=netframework-4.8
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.