1

I am trying to create a webpage that allow users to unsubscribe from receiving the report.

So far I have created the page. users are able to see all the reports that they are receiving

I have also written an "update replace" statement that, unfortunately this updates everything.

My question is how do I modify my code to only delete one line at a time even if the same info is in the next line

Please see my code below

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    System.Web.UI.WebControls.Label rollno = GridView1.Rows[e.RowIndex].FindControl("Label1") as System.Web.UI.WebControls.Label;
    SqlConnection con = new SqlConnection();
    con.ConnectionString = ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;
    con.Open();
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "UPDATE Subscriptions SET Subscriptions.ExtensionSettings = REPLACE('Subscriptions.ExtensionSettings', @ReportSearch, '') WHERE Subscriptions.ExtensionSettings like '@ReportSearch'" ;
    cmd.Parameters.AddWithValue("ReportSearch", TxtSearch.Text);
    cmd.Connection = con;
    cmd.ExecuteNonQuery();
    GridView1.EditIndex = -1;
    GridView1.DataSource = SqlDataSource1;
    GridView1.DataBind();
}
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
Ola
  • 11
  • 1
  • `'@ReportSearch'` should be `@ReportSearch`. It shouldn't have quotes around it. – mjwills Nov 28 '18 at 12:03
  • Possible duplicate of [How to update top 1 row in SQL Server](https://stackoverflow.com/questions/23673348/how-to-update-top-1-row-in-sql-server) – mjwills Nov 28 '18 at 12:06
  • @mjwills thanks for your reply it's not quite the same, my issue is with the c# code not the sql – Ola Nov 28 '18 at 14:18
  • @s.akbari can you please have a look at this for me please I am new to asp.net and c# – Ola Nov 28 '18 at 15:53
  • First what is your SqlDataSource1, it is not updated anywhere in this code. Also share some data and what you type in the search text. To update just one row you must use one unique identifier in your update statement. You started that with 'rollno' but never used it. Probably that is your issue. – SehaxX Nov 29 '18 at 08:00

0 Answers0