Avatar of Ron Renninger
Ron Renninger

asked on 

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

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

C#

Avatar of undefined
Last Comment
Ron Renninger
ASKER CERTIFIED SOLUTION
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Ron Renninger
Ron Renninger

ASKER

Thank you it was hard to find after looking at the code for a long time
Avatar of Ron Renninger

ASKER

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

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo