Hello,
I have a simple program with a specific culture, set to "ro-RO".
For example:
en-EN is 1,000.20
ro-RO is 1.000,20
those number ar the same
I have some math calculation with result is a DECIMAL, if my pc has set the regional to en-EN, the data is save oK in my database, if my pc has regional set to ro-RO, when i save the decimal in database is 100,020.00.
If i convert the number to Double the number is save proper.
Any suggestion what is the best solution?
Some code:
I retrive some data from database like this:
DateTime[] UltimaInregistrareGr = new DateTime[CategorieProdus.Rows.Count];
decimal[] SoldGramaj = new decimal[CategorieProdus.Rows.Count];
int[] IdGramaj = new int[CategorieProdus.Rows.Count];
for (int i = 0; i < CategorieProdus.Rows.Count; ++i)
{
int NrCatCategorie = Convert.ToInt32(CategorieProdus.Rows[i]["id_categorie"].ToString());
Program.Connection.CommandText = "SELECT regGramaj.regGramaj_id, regGramaj.regGramaj_date, regGramaj.regGramaj_soldinitial, regGramaj.regGramaj_soldfinal, IIF(regGramaj.regGramaj_categorie Is Null, 0, regGramaj.regGramaj_categorie) AS RegRaportCategorie " +
"FROM regGramaj, [SELECT MAX(regGramaj.regGramaj_date) FROM regGramaj]. AS maxdate " +
"WHERE regGramaj.regGramaj_categorie=@regGramaj_categorie";
Program.Connection.AddParameter("@regGramaj_categorie", NrCatCategorie);
DataTable TableSold = new DataTable();
Program.Connection.FillDataTable(TableSold, true);
if (TableSold.Rows.Count != 0)
{
for (int j = 0; j < TableSold.Rows.Count; ++j)
{
UltimaInregistrareGr[i] = Convert.ToDateTime(TableSold.Rows[j]["regGramaj_date"].ToString());
if (UltimaInregistrareGr[i] == DateTime.Today)
SoldGramaj[i] = Convert.ToDecimal(TableSold.Rows[j]["regGramaj_soldinitial"].ToString());
else
SoldGramaj[i] = Convert.ToDecimal(TableSold.Rows[j]["regGramaj_soldfinal"].ToString());
IdGramaj[i] = Convert.ToInt32(TableSold.Rows[j]["regGramaj_id"].ToString());
}
}
else
{
SoldGramaj[i] = 0;
IdGramaj[i] = 0;
}
}
and after sone math calculation i save the result like this:
Program.Connection.CommandText = "INSERT INTO regGramaj (regGramaj_date, regGramaj_soldinitial, regGramaj_intrari, regGramaj_vanzare, regGramaj_soldfinal, regGramaj_categorie) values (@regGramaj_date, @regGramaj_soldinitial, @regGramaj_intrari, @regGramaj_vanzare, @regGramaj_soldfinal, @regGramaj_categorie)";
Program.Connection.AddParameter("@regGramaj_date", DateTime.Today);
Program.Connection.AddParameter("@regGramaj_soldinitial", SoldGramaj[i]);
Program.Connection.AddParameter("@regGramaj_intrari", IntrariGramaj[i]);
Program.Connection.AddParameter("@regGramaj_vanzare", IesireGramaj[i]);
Program.Connection.AddParameter("@regGramaj_soldfinal", GramajFinal);
Program.Connection.AddParameter("@regGramaj_categorie", CatProdusNr[i]);
Program.Connection.ExecuteNonQuery();
Program.Connection.CommitTranzaction();