在gridview中不删除行

在gridview中不删除行

本文介绍了在gridview中不删除行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void gid_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Label lblname = (Label)gid.Rows[e.RowIndex].FindControl("lblname");
            con.Open();
          string cmdd = "DELETE from grid where name='" + lblname + "'";
          
          cmd = new SqlCommand(cmdd,con);
          cmd.Parameters.AddWithValue("@name", lblname.Text);
           
            cmd.ExecuteNonQuery();
            con.Close();
            fill_show();
        }



代码无法正常工作

请给出解决方案



我尝试了什么:




code not work properly
please give solution

What I have tried:

protected void gid_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Label lblname = (Label)gid.Rows[e.RowIndex].FindControl("lblname");
            con.Open();
          string cmdd = "DELETE from grid where name='" + lblname + "'";
          
          cmd = new SqlCommand(cmdd,con);
          cmd.Parameters.AddWithValue("@name", lblname.Text);
           
            cmd.ExecuteNonQuery();
            con.Close();
            fill_show();
        }

推荐答案

string cmdd = "DELETE from grid where name=@name ";
            cmd = new SqlCommand(cmdd, con);
            cmd.Parameters.AddWithValue("@name", lblname.Text);
            cmd.ExecuteNonQuery();


这篇关于在gridview中不删除行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 09:50