如何在gridview中删除? [英] How do I do delete in gridview?

查看:50
本文介绍了如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆