troubleshooting Question

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

Avatar of Ron Renninger
Ron Renninger asked on
C#
3 Comments1 Solution524 ViewsLast Modified:
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)


 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));
ASKER CERTIFIED SOLUTION
Shaun Kline
Lead Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros