Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There is no error but the row cant be deleted

What I have tried:

try
{

using (SqlConnection conn = new SqlConnection(strConnString))
{

con.Open();
string strq = ("Delete LoanRates where LoanTerm=@LoanTerm and LoanRate=@LoanRate and LoanType=@LoanType");
SqlCommand insert = new SqlCommand(strq, con);

insert.Parameters.AddWithValue("@LoanTerm", Convert.ToInt32(this.GridView1.Rows[e.RowIndex].Cells[2].Text.Trim()));
insert.Parameters.AddWithValue("@LoanRate", Convert.ToDouble(this.GridView1.Rows[e.RowIndex].Cells[3].Text.Trim()));
insert.Parameters.AddWithValue("@LoanType", this.GridView1.Rows[e.RowIndex].Cells[1].Text.Trim());


con.Close();
}


}
catch (Exception ex) {

lblMessage.Text = "Error: " + ex.Message;
}
Posted
Updated 28-Jul-16 3:47am

1 solution

add this line

C#
insert.Parameters.AddWithValue("@LoanType", this.GridView1.Rows[e.RowIndex].Cells[1].Text.Trim());
   insert.ExecuteNonQuery();


by the way, give meaningful names to the variables as

C#
SqlCommand cmdDelete = new SqlCommand(strq, con);
 
Share this answer
 
v4
Comments
Member 12652110 28-Jul-16 9:50am    
It still does not work
Karthik_Mahalingam 28-Jul-16 9:55am    
open sql studio and run the query and check where the row is availble for the condition you are passing
select * from LoanRates where LoanTerm=@LoanTerm and LoanRate=@LoanRate and LoanType=@LoanType
Member 12652110 28-Jul-16 9:52am    
oops so sorry it actually works
Karthik_Mahalingam 28-Jul-16 9:55am    
ok.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900