when i debug, from gridviewbind();
deleteCart(pic);
it stops,and it is not entering into public void deleteCart(string orderID), what could be a problem?
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
gridviewbind();
}
}
public void gridviewbind()
{
SqlConnection con = new SqlConnection("constring1");
string str = "select * from Products INNER JOIN orders on Products.picID=orders.productID";
SqlCommand cmd = new SqlCommand(str, con);
con.Open();
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("picID", typeof(int)));
dt.Columns.Add(new DataColumn("title", typeof(string)));
dt.Columns.Add(new DataColumn("price", typeof(int)));
dt.Columns.Add(new DataColumn("dateAdded", typeof(DateTime)));
dt.Columns.Add(new DataColumn("picURL", typeof(string)));
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
DataRow dr = dt.NewRow();
dr["picID"] = Convert.ToInt32(reader["picID"]);
dr["title"] = reader["title"];
dr["price"] = Convert.ToInt32(reader["price"]);
dr["dateAdded"] = reader["dateAdded"];
dr["picURL"] = ResolveUrl("~/images/" + reader["picURL"]);
dt.Rows.Add(dr);
}
reader.Close();
con.Close();
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void Gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "removeRow")
{
string pic = Convert.ToString(e.CommandArgument);
// GridViewRow row = GridView1.Rows[pic];
// deleteCart(row.Cells[1].Text.ToString());
gridviewbind();
deleteCart(pic);
}
}
public void deleteCart(string orderID)
{
using (SqlConnection con = new SqlConnection("constring1"))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "delete from orders where orderID=@orderID";
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@orderID", orderID);
con.Open();
var temp = cmd.ExecuteNonQuery();
con.Close();
}
}
}