11,578 questions
Check this:
details.TotalAmount = details.Items.Sum(i => decimal.Parse(i.Price) * int.Parse(i.Quantity));
Or maybe adjust the types of Price and Quantity.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
}
public void SaveBillDetails(BillDetail details)
{
SqlConnection con = new SqlConnection(ConnectionString);
try
{
con.Open();
SqlCommand cmd = new SqlCommand("spt_saveEBillDetails", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@CustomerName",details.CustomerName);
cmd.Parameters.AddWithValue("@MobileNumber",details.MobileNumber);
cmd.Parameters.AddWithValue("@Address",details.Address);
cmd.Parameters.AddWithValue("@TotalAmount",details.TotalAmount);
SqlParameter outputPara = new SqlParameter();
outputPara.DbType = DbType.Int32;
outputPara.Direction = ParameterDirection.Output;
outputPara.ParameterName = "@Id";
cmd.Parameters.Add(outputPara);
cmd.ExecuteNonQuery();
int id = int.Parse(outputPara.Value.ToString());
if(details.Items.Count> 0)
Note : Please help out guru............ Thanks
details.TotalAmount = details.Items.Sum(i => i.Price * i.Quantity); // This is where my issue is
Check this:
details.TotalAmount = details.Items.Sum(i => decimal.Parse(i.Price) * int.Parse(i.Quantity));
Or maybe adjust the types of Price and Quantity.
No need to use decimal.Parse or int.Parse conceptual example
SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
CREATE PROCEDURE spDemo @Parm DECIMAL(18, 2) OUT
AS
BEGIN
SET NOCOUNT ON;
SET @Parm = 93.77;
END;
GO
Code
public static void StoredDemo()
{
using var cn = new SqlConnection(ConnectionString());
using var cmd = new SqlCommand("spDemo", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Parm", SqlDbType.Decimal)
.Direction = ParameterDirection.Output;
cn.Open();
cmd.ExecuteNonQuery();
int quantity = 10;
decimal value = (decimal)cmd.Parameters["@Parm"].Value ;
decimal result = value * quantity;
}
Thanks for your contributions @Viorel and @Karen
I used this below and it worked for me
details.TotalAmount = details.Items.Sum(i => int.Parse(i.Price) * int.Parse(i.Quantity));
I converted both strings to int using parse..