System.ArgumentException: 'Column 'TotalPrice' does not belong to table .
public partial class Invoice : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter sda;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["userId"] != null)
{
if (Request.QueryString["id"] != null)
{
rOrderItem.DataSource = GetOrderDetails();
rOrderItem.DataBind();
}
}
else
{
Response.Redirect("Login.aspx");
}
}
}
DataTable GetOrderDetails()
{
double grandTotal = 0;
con = new SqlConnection(Connection.GetConnectionString());
cmd = new SqlCommand("Invoice", con);
cmd.Parameters.AddWithValue("@Action", "INVOICEBYID");
cmd.Parameters.AddWithValue("@PaymentId", Convert.ToInt32(Request.QueryString["id"]));
cmd.Parameters.AddWithValue("@UserId", Session["userId"]);
cmd.CommandType = CommandType.StoredProcedure;
sda = new SqlDataAdapter(cmd);
dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
foreach (DataRow drow in dt.Rows)
{
grandTotal += Convert.ToDouble(drow["TotalPrice"]);
}
}
DataRow dr = dt.NewRow();
dr["TotalPrice"] = grandTotal;
dt.Rows.Add(dr);
return dt;
}
}
CREATE PROCEDURE Invoice
@Action VARCHAR(10),
@PaymentId INT = NULL,
@UserId INT = NULL,
@OrderDetailsId INT = NULL,
@Status VARCHAR(50) = NULL
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- GET INVOICE BY ID
IF @Action = 'INVOICEBYID'
BEGIN
SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 1)) AS [SrNo], o.OrderNo, p.Name, p.Price, o.Quantity,
(p.Price * o.Quantity) as TotalPrice, o.OrderDate, o.Status FROM Orders o
INNER JOIN Products p ON p.ProductsId = o.ProductId
WHERE o.PaymentId = @PaymentId AND o.UserId = @UserId
END
END