使用复选框删除按钮代码 [英] Delete button code using checkbox

查看:94
本文介绍了使用复选框删除按钮代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Iselibrary
{
public partial class Delete : Form
{
SqlConnection vid = new SqlConnection("Data Source=.;Initial Catalog=iselibrary;Integrated Security=True");
//private object item;

public Delete()
{
InitializeComponent();
}
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{

}

private void button1_Click_1(object sender, EventArgs e)
{
this.Close();
Home home = new Home();
home.Show();
}

private void Update_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'iselibraryDataSet1.T_BOOK_ISSUE_TABLE' table. You can move, or remove it, as needed.
this.t_BOOK_ISSUE_TABLETableAdapter.Fill(this.iselibraryDataSet1.T_BOOK_ISSUE_TABLE);

}

private void button2_Click(object sender, EventArgs e)
{
String str = "Select * from T_BOOK_ISSUE_TABLE where (USN like '%' + @search + '%')";
SqlCommand xp = new SqlCommand(str, vid);
xp.Parameters.Add("@search", SqlDbType.NVarChar).Value = textBox1.Text;


vid.Open();
xp.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = xp;
DataSet dat = new DataSet();
da.Fill(dat, "USN");
dataGridView1.DataSource = dat;
dataGridView1.DataSource = dat.Tables[0];
vid.Close();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}
// 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  /* as error occurs here I have not completed the code*/
}
}
}
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

}
}
}





谢谢



尽快我完成了ise.T_BOOK_ISSUE_TABLE。在If循环中,我没有得到删除的下拉列表。为什么这样?并且错误表示为:'对象查询< T_BOOK_ISSUE_TABLE>'不包含'remove'的定义,并且没有扩展方法'remove'接受类型'Object Query< T_BOOK_ISSUE_TABLE>'的第一个参数' (你错过了指令或汇编引用吗?)

请让我知道我哪里出错或者那里的任何人请帮我写复选框的删除按钮代码检查。(#windows form app)希望有人在论坛帮助....

谢谢



THANK YOU

As soon as i complete ise.T_BOOK_ISSUE_TABLE. in If loop, I dont get a dropdown for Remove. Why so? and error says as:'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?)
Please let me know where im going wrong or anyone out there please help me to write delete button code using checkbox checked.(#windows form app) Hope anyone in forum helps....
Thank you

推荐答案



而不是第一个或默认为什么你不能使用find或single或者

if(issu!= null)

{

entity.tablename.remove(issu);

entity.savechanges();

}



i hope这适用于你......
Hi,
instead of first or default why cant u go with find or single or where
if(issu !=null)
{
entity.tablename.remove(issu);
entity.savechanges();
}

i hope this works for u.....


GOT SOLUTION 这里是....





GOT SOLUTION here it is....


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);
           }


这篇关于使用复选框删除按钮代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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