Jitendra Kumar

Jitendra Kumar

  • 1.8k
  • 189
  • 16.7k

Can you explain this code? I am not able to get this?

Aug 5 2018 11:55 PM
protected void btnaddtocart_Click(object sender, EventArgs e)
{
if (Session["cart"] == null)
{
SqlParameter[] prm = new SqlParameter[1];
ds = new DataSet();
prm[0] = new SqlParameter("@id", pid);
ds = an.ReturnSpParamDataSet("tbl_products_info12", prm);
if (ds.Tables[0].Rows.Count > 0)
{
DataSet pds;
pds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("pid"));
dt.Columns.Add(new DataColumn("productname"));
dt.Columns.Add(new DataColumn("quantity"));
dt.Columns.Add(new DataColumn("price"));
dt.Columns.Add(new DataColumn("discount"));
dt.Columns.Add(new DataColumn("discountprice"));
dt.Columns.Add(new DataColumn("shippingcharge"));
pds.Tables.Add(dt);
DataRow dr = pds.Tables[0].NewRow();
dr["pid"] = pid;
dr["productname"] = ds.Tables[0].Rows[0]["product_name"].ToString();
dr["quantity"] = txtquantity.Text;
dr["price"] = ds.Tables[0].Rows[0]["price"].ToString();
dr["discount"] = ds.Tables[0].Rows[0]["discount"].ToString();
dr["discountprice"] = ds.Tables[0].Rows[0]["discountprice"].ToString();
dr["shippingcharge"] = ds.Tables[0].Rows[0]["shipingcharge"].ToString();
pds.Tables[0].Rows.Add(dr);
Session.Add("cart", pds);
}
Response.Redirect("~/cart.aspx");
}
else
{
DataSet pds = (DataSet)Session["cart"];
SqlParameter[] prm = new SqlParameter[1];
ds = new DataSet();
prm[0] = new SqlParameter("@id", pid);
ds = an.ReturnSpParamDataSet("tbl_products_info12", prm);
if (ds.Tables[0].Rows.Count > 0)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("pid"));
dt.Columns.Add(new DataColumn("productname"));
dt.Columns.Add(new DataColumn("quantity"));
dt.Columns.Add(new DataColumn("price"));
dt.Columns.Add(new DataColumn("discount"));
dt.Columns.Add(new DataColumn("discountprice"));
dt.Columns.Add(new DataColumn("shippingcharge"));
pds.Tables.Add(dt);
DataRow dr = pds.Tables[0].NewRow();
dr["pid"] = pid;
dr["productname"] = ds.Tables[0].Rows[0]["product_name"].ToString();
dr["quantity"] = txtquantity.Text;
dr["price"] = ds.Tables[0].Rows[0]["price"].ToString();
dr["discount"] = ds.Tables[0].Rows[0]["discount"].ToString();
dr["discountprice"] = ds.Tables[0].Rows[0]["discountprice"].ToString();
dr["shippingcharge"] = ds.Tables[0].Rows[0]["shipingcharge"].ToString();
pds.Tables[0].Rows.Add(dr);
Session.Add("cart", pds);
}
Response.Redirect("~/cart.aspx");
}
}

Answers (2)