0

I've created a gridview that contains a "DELETE" button, to delete the row.

My Code :

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    string username = (string)Session["user"];
    string path = this.GridView1.SelectedRow.Cells[3].Text;
    Cart cart = new Cart();
    cart.Deleteitem(path,username);
}

public void Deleteitem(string path, string username)
{
    string sql = string.Format("DELETE FROM Cart WHERE path = '{0}' AND userid = '{1}' ", path, username);
    DBC dbc = new DBC();
    dbc.InsertUpdateDelete(sql);
}

 public void InsertUpdateDelete(string sql)
{
    this.cmd = new OleDbCommand(sql, this.con);
    this.con.Open();
    this.cmd.ExecuteNonQuery();
    this.con.Close();
}

My problem that when I clock the "DELETE" button, nothing happen, nothing deleted, what's the problem ?

braX
  • 11,506
  • 5
  • 20
  • 33

2 Answers2

0

My guess is you're probably throwing an error but you don't see it. Wrap your call to this.cmd.ExecuteNonQuery(); in a try...catch...finally block then step through it and see if you catch an error.

I've seen "errors" prevent an update but they aren't true errors - like the language being set to English instead of Default.

Tim
  • 4,051
  • 10
  • 36
  • 60
-1

Remove the single quotes around {}.

string.Format("DELETE FROM Cart WHERE path = {0} AND userid = {1}", path, username);
wazz
  • 4,953
  • 5
  • 20
  • 34
  • If userid is a number, just remove the quotes around that one. Note also that you're passing in `username` but your sql says `userid`. – wazz Jun 11 '18 at 21:30