MikeMCSD
asked on
System.InvalidCastException error
CREATE PROCEDURE cartTotal
(@CartID char(36), @gift smallint OUTPUT)
SELECT @gift = SUM(Quantity)
FROM ShoppingCart
WHERE ShoppingCart.CartID = @CartID AND Gift = 1
Gift is a bit field. Quantity an int.
What I want to do is to total the Quantity field for every row where Gift = 1.
Example:
Gift Quantity
1 1
0 1
1 3 so in this case @gift would equal 4.
I tried the above but get an error:
Exception Details:
System.InvalidCastExceptio n: Cast from type 'DBNull' to type 'Short' is not valid
details.gift = CType(command.Parameters(" @gift").Va lue, Short)
But this line works in above: SELECT @gift = count(*) . . . but I need to add the
Quantity to the count for every row where Gift = 1.
thanks
(@CartID char(36), @gift smallint OUTPUT)
SELECT @gift = SUM(Quantity)
FROM ShoppingCart
WHERE ShoppingCart.CartID = @CartID AND Gift = 1
Gift is a bit field. Quantity an int.
What I want to do is to total the Quantity field for every row where Gift = 1.
Example:
Gift Quantity
1 1
0 1
1 3 so in this case @gift would equal 4.
I tried the above but get an error:
Exception Details:
System.InvalidCastExceptio
details.gift = CType(command.Parameters("
But this line works in above: SELECT @gift = count(*) . . . but I need to add the
Quantity to the count for every row where Gift = 1.
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER