public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.bind();
}
public void bind()
{
string sql = "select * from titles";
this.dataGridView1.DataSource = dal.dao.getTable(sql);
}
private void button1_Click(object sender, EventArgs e)
{
string xzid = "";
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
DataGridViewRow row = dataGridView1.Rows[i];
if (row.Cells[0].Value != null)
{
if (bool.Parse(row.Cells[0].Value.ToString()) == true)
{
int row1 = row.Index;
xzid =xzid+"'"+ this.dataGridView1[1, row1].Value.ToString() +"'"+",";
}
}
}
if (xzid.Length > 0)
{
xzid = xzid.Substring(0, xzid.Length - 1);
//MessageBox.Show(xzid);
}
string sql1 = string.Format("delete from titles where title_id in ({0})", xzid);
if (MessageBox.Show("确实要删除选中的行吗? 注意:删除后就无法恢复了!", "警告",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int g = dal.dao.InsertOne(sql1);
if (g > 0)
{
MessageBox.Show("删除成功~~");
}
else
MessageBox.Show("删除失败!!!");
}
else
return;
bind();
}
}
{
public Form1()
{
InitializeComponent();
this.bind();
}
public void bind()
{
string sql = "select * from titles";
this.dataGridView1.DataSource = dal.dao.getTable(sql);
}
private void button1_Click(object sender, EventArgs e)
{
string xzid = "";
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
DataGridViewRow row = dataGridView1.Rows[i];
if (row.Cells[0].Value != null)
{
if (bool.Parse(row.Cells[0].Value.ToString()) == true)
{
int row1 = row.Index;
xzid =xzid+"'"+ this.dataGridView1[1, row1].Value.ToString() +"'"+",";
}
}
}
if (xzid.Length > 0)
{
xzid = xzid.Substring(0, xzid.Length - 1);
//MessageBox.Show(xzid);
}
string sql1 = string.Format("delete from titles where title_id in ({0})", xzid);
if (MessageBox.Show("确实要删除选中的行吗? 注意:删除后就无法恢复了!", "警告",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int g = dal.dao.InsertOne(sql1);
if (g > 0)
{
MessageBox.Show("删除成功~~");
}
else
MessageBox.Show("删除失败!!!");
}
else
return;
bind();
}
}