使用复选框删除按钮代码

本文关键字:按钮 代码 删除 复选框 | 更新日期: 2023-09-27 18:18:34

// Delete Button Details//
private void button3_Click(object sender, EventArgs e)
{
    iselibraryEntities ise = new iselibraryEntities();
    foreach(var item in dataGridView1.Rows)
    {
        DataGridViewRow row = item as DataGridViewRow;
        if(row.Selected)
        {
            string usn = row.Cells["USN"].Value.ToString();
            var issu = ise.T_BOOK_ISSUE_TABLE.FirstOrDefault(a => a.USN.Equals(usn));
            if(issu!=null)
            {
                ise.T_BOOK_ISSUE_TABLE.remove
            } 
        }
    }

问题是,在ise.T_BOOK_ISSUE_TABLE之后的if循环中,我没有得到remove下拉列表

显示'Object Query<T_BOOK_ISSUE_TABLE>' does not contain a definition for 'remove' and no extension method 'remove' accepting a first argument of type'Object Query<T_BOOK_ISSUE_TABLE>'could be found(are you missing a directive or an assembly reference?)

使用复选框删除按钮代码

找到答案了....

private void button3_Click(对象发送者,EventArgs e)

   {
       var selectedidlist = new List<string>();
       for (var rownum = 0; rownum < dataGridView1.Rows.Count; rownum++)
       {
           if (dataGridView1.Rows[rownum].Cells["Column1"].Value!=null && ((bool)(dataGridView1.Rows[rownum].Cells["Column1"]).Value))
           {
               selectedidlist.Add(dataGridView1.Rows[rownum].Cells["USN"].Value.ToString());
           }
       }
       if (selectedidlist.Count > 0)
       {
           var selectedListString = selectedidlist.Aggregate((current, next) => current + ", " + next);
           String str = "delete  from T_BOOK_ISSUE_TABLE where USN in (@search)";
           SqlCommand xp = new SqlCommand(str, vid);
           xp.Parameters.Add("@search", SqlDbType.NVarChar).Value = selectedListString;
           vid.Open();
           xp.ExecuteNonQuery();
           vid.Close();
           Delete_Load(null, null);
       }