Currency fields 1.99 saving as 199 on Access

Asked

Viewed 223 times

1

I have a problem when I go to save the data of fields currency or decimal in an Access database using Visual Studio components.

When I save something like 1.99m or has 1,99 in the textbox the data goes to the database as 199. In short the comma is removed and I get the values multiplied by 100. How can I fix this? I’ve tried things like decimal.parse and Convert.toDecimal in addition to playing directly the dice in querys that I created:

tableAdapterprodutosTableAdapter.UpdateEstoquePreco(id, **1.99m**);

The problem occurs in any operation both insert how much in update.

  • What is the date type of the variable that receives this value (currency)?

  • Decimal I’m doing a test right now with a Double but by default is Decimal

  • Searching I found the following material, but as I used the tableAdapter components and datasets throughout the system I can’t apply it! but follows the code!

  • You commented that you tried with 1.99 too... if you go straight to the bank and enter 1.99 it accepts?

  • Yes in the bank all right including with those commands I put below in the answer too, what I realized eh that there seems to be a certain incompatibility with the access and the components of the visual studio (dataset, Datatableadapter) finally those that you create automatically by dragging the elements from the datasource to the form, but as I said... it seems because it is only with the floating point numeric fields that I am having problems I tried to change to Double but in the same!

2 answers

2


I decided editing directly in Dataset Designer, somehow it was setting providerType to Numeric, all I did was change to currency inserir a descrição da imagem aqui

1

Searching I found the following material, but as I used the tableAdapter components and datasets throughout the system I can’t apply it! but follows the code!

public void Gravar(String Nome, DateTime Data, Decimal Salario, Boolean Status)
{
  using (OleDbConnection Conexao = new OleDbConnection(StringConexao))
  {
    Conexao.Open();
    using (OleDbCommand Commando = Conexao.CreateCommand())
    {
        Commando.CommandType = CommandType.Text;
        Commando.CommandText = "INSERT INTO Valores(Nome, Data, Salario, Status) VALUES(@Nome, @Data, @Salario, @Status);";
        Commando.Parameters.Add("@Nome", OleDbType.VarChar, 50).Value = Nome;
        Commando.Parameters.Add("@Data", OleDbType.Date).Value = Data;
        Commando.Parameters.Add("@Salario", OleDbType.Currency).Value = Salario;
        Commando.Parameters.Add("@Status", OleDbType.Boolean).Value = Status;
        Commando.ExecuteNonQuery();
    }
    Conexao.Close();
  }
}
  • Try using Oledbtype.Decimal in Salary

  • So... this code doesn’t apply because I’m using the ready-made components of Visual Studio

  • http://www.databaseskill.com/2092815/ take a look at this table and here http://referencesource.microsoft.com/#System.Data/data/System/Data/Oledb/Oledbtype.Cs has the decimal property yes! By default it seems Ole uses Money and does not format properly because Decimal must be using the Resource Culture formatting!

  • I tried several ways, including with Culture but without success, some idea of how I could make this conversion?

  • Thanks @Premiere managed to get the answer by searching for your links.

  • Quiet. As soon as possible mark the answer you posted as correct!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.