如何在gridview中删除? [英] How do I do delete in gridview?
问题描述
没有错误,但行无法删除
我尝试过:
尝试
{
使用(SqlConnection conn = new SqlConnection(strConnString))
$
con.Open();
string strq =(删除LoanRates,其中LoanTerm = @ LoanTerm和LoanRate = @ LoanRate和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());
< br $>
con.Close();
}
}
catch(exception ex){
lblMessage.Text =错误:+ ex.Message;
}
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;
}
推荐答案
添加此行
add this line
insert.Parameters.AddWithValue("@LoanType", this.GridView1.Rows[e.RowIndex].Cells[1].Text.Trim());
insert.ExecuteNonQuery();
顺便说一下,给变量赋予有意义的名字as
by the way, give meaningful names to the variables as
SqlCommand cmdDelete = new SqlCommand(strq, con);
这篇关于如何在gridview中删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!