hello all

how to express parameter with decimal (which has 2 scale)


//----------------------------
mysqlda.UpdateCommand.Parameters.Add("@Name", MySqlDbType.VarChar,40, "Name");
mysqlda.UpdateCommand.Parameters.Add("@Kode", MySqlDbType.VarChar, 8, "Kode");
mysqlda.UpdateCommand.Parameters.Add("@Price", MySqlDbType.Decimal ,10,2, "Price");

//----------------------------
line 3 give me error

thanks
denny

you are trying to assign a string ("Price") to a decimal field. Is Price a variable in your code? If so, remove the quote marks. If not, you need a decimal value to assign to it.

mysqlda.UpdateCommand.Parameters.Add("@Price", MySqlDbType.Decimal ,10,2, "Price");

The 3rd parameter in the Add() method is the Size, and its must me an integer. So no commas in between. You dont specify and such thing as in the database, where you specify the number of decimals (like 10, 2 - 10 numbers lenght,and precision of these 2 decimals).
Here you only specify the size of the value).
It represents The maximum size, in bytes, of the data within the column.
This parameter is not so important, because Size affects only the input value of a parameter. Return values and output parameters are not affected by this property.

You can set the size to -1, to ensure that you are getting the entire data from the backend without truncation.

Here is what you can all set for particular parameter:

SqlParameter myParameter = new SqlParameter("@Price", SqlDbType.Decimal);
    myParameter.Value = /some value
    myParam.Size = -1; //or you can set it to 5
    myParameter.Precision = 8;
    myParameter.Scale = 4;

This is only to show you how you can set parameters for a SqlParameter class.
You can do something like this:

mysqlda.UpdateCommand.Parameters.Add("@Price", MySqlDbType.Decimal ,5, "Price");

hi all ,hi Mitja

it work
thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.