"Failed to convert parameter value from a String to a Decimal."

Ron Renninger
Ron Renninger used Ask the Experts™
on
Below is the Procedure, code calling procedure and the last line is the varable passed

CREATE PROCEDURE AddPrice
(@ProductId INT,
@ProductSize VARCHAR(25),
@Price MONEY,
@SalePrice MONEY)
[/b]AS
INSERT INTO PriceTable(ProductId,ProductSize, Price, SalePrice)
VALUES(@ProductId, @ProductSize, @Price, @SalePrice)

Open in new window



 public static bool AddPrice(string ProductId, string ProductSize, decimal Price, decimal SalePrice)
    {
        DbCommand comm = genericDataAccess.CreateCommand();
        comm.CommandText = "AddPrice";

        DbParameter param = comm.CreateParameter();
        param.ParameterName = "@ProductId";
        param.Value = ProductId;
        param.DbType = DbType.Int32;
        comm.Parameters.Add(param);

        param = comm.CreateParameter();
        param.ParameterName = "@ProductSize";
        param.Value = ProductSize;
        param.DbType = DbType.String;
        comm.Parameters.Add(param);

        param = comm.CreateParameter();
        param.ParameterName = "@Price";
        param.Value = "Price";
        param.DbType = DbType.Decimal;
        comm.Parameters.Add(param);

        param = comm.CreateParameter();
        param.ParameterName = "@SalePrice";
        param.Value = SalePrice;
        param.DbType = DbType.Decimal;
        comm.Parameters.Add(param);

        // result will represent the number of changed rows
        int result = -1;

        try
        {
            // execute the stored procedure
            result = genericDataAccess.ExecuteNonQuery(comm);
        }
        catch
        {
            // any errors are loggin in genericdata access we ignore them here

        }
        return (result != -1);
    }

bool success = CatalogAccessClass1.AddPrice(ProductId.Text, ProductSize.Text, Convert.ToDecimal(Price.Text) , Convert.ToDecimal(SalePrice.Text));

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Lead Software Engineer
Commented:
This is wrong:
 param.Value = "Price";

It should be:
 param.Value = Price;

Author

Commented:
Thank you it was hard to find after looking at the code for a long time

Author

Commented:
It is asp.net using C# but i did not see it in the drop down list

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial