i have one table for cart have to insert those values into another table but its takes only the last value
my code as follows
if (Convert.ToDecimal(Label1.Text) > 0)
{
if (Convert.ToDecimal(Label1.Text) > 0)
{
string proid = Application["id"].ToString();
con.Open();
da = new SqlDataAdapter("select tpd.productid,tpd.productname,tpd.ProductImage,tpd.price,tpd.qty,tpd.totalcost,tpd.cdate from rsa_addtocart tpd where tpd.productid=" + proid + " ", con);
ds = new DataSet();
da.Fill(ds, "tbl_tpd");
if (ds.Tables.Count > 0 && ds.Tables["tbl_tpd"].Rows.Count > 0)
{
using (var command = new SqlCommand("insert into rsa_Orderconfirmation(UserId, productid, productname, ProductImage, price, qty, totalcost, cdate) values (@UserId, @productid, @productname, @ProductImage, @price, @qty, @totalcost, @cdate)", con))
{
for (int z = 0; z < this.Gridcart.Rows.Count; z++)
{
command.Parameters.Clear();
command.Parameters.AddWithValue("@UserId", Session["users"]);
command.Parameters.AddWithValue("@productid", ds.Tables[0].Rows[0][0]);
command.Parameters.AddWithValue("@productname", ds.Tables[0].Rows[0][1]);
command.Parameters.AddWithValue("@ProductImage", ds.Tables[0].Rows[0][2]);
command.Parameters.AddWithValue("@price", ds.Tables[0].Rows[0][3]);
command.Parameters.AddWithValue("@qty", ds.Tables[0].Rows[0][4]);
command.Parameters.AddWithValue("@totalcost", ds.Tables[0].Rows[0][5]);
command.Parameters.AddWithValue("@cdate", DateTime.Now);
if (con.State != ConnectionState.Open)
{
con.Open();
try
{
command.ExecuteNonQuery();
}
finally
{
con.Close();
}
}
else
{
command.ExecuteNonQuery();
}
}
Response.Redirect("~/BillingDetails.aspx");
con.Close();
}
}
}
only its inserts the last value i want to insert what are the values in cart table
how it can be done someone can help me?