//选中哪个删除 private void button2_Click(object sender, EventArgs e) { DialogResult RSS = MessageBox.Show(this, "确定要删除选中行数据码?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); switch (RSS) { case DialogResult.Yes: for (int i = this.dataGridView1.SelectedRows.Count; i > 0; i--) { int ID = Convert.ToInt32(dataGridView1.SelectedRows[i - 1].Cells[0].Value); dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[i - 1].Index); //使用获得的ID删除数据库的数据 string sql = "delete from Ls_Mms_Info where id=" + ID; int s = Convert.ToInt32(SqlDesigner.ExecuteNoQuery(sql)); //cl是操作类的一个对像,Execute()是类中的一个方法 if (s != 0) { MessageBox.Show("成功删除选中行数据!"); } } break; case DialogResult.No: break; } }
//修改保存 private void button4_Click(object sender, EventArgs e) { int i = SqlDesigner.ExecuteNoQuery("update Ls_Mms_Info set info='" + textBox1.Text + "',more='" + textBox2.Text + "',name='" + textBox3.Text + "' where id=" + id); if (i > 0) { MessageBox.Show("修改数据成功"); } else { MessageBox.Show("修改数据不成功"); } }
private void button1_Click(object sender, EventArgs e) { int i = SqlDesigner.ExecuteNoQuery("insert into Ls_Mms_Info(info,more,name) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')"); if (i > 0) { MessageBox.Show("数据添加成功"); } else { MessageBox.Show("数据添加不成功"); } }