使用复选框删除按钮代码

时间:2015-10-21 07:17:36

标签: c# .net visual-studio sql-server-2008

// 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循环中没有得到删除的下拉列表。

错误表示为'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?)

1 个答案:

答案 0 :(得分:0)

这是GOT解决方案....

private void button3_Click(object sender,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);
       }