本文介绍了从 DataGridView winforms 中的数据库中删除数据行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从数据库中删除该行数据,目前我可以通过点击删除按钮删除该行数据,但是数据库表没有更新,我该怎么做?
i want to delete the row of data from the database, currently i can delete the row of data by clicking on the delete button, but the database Table is not updated, how do i do so?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace project
{
public partial class frmTestPrint : Form
{
public frmTestPrint()
{
InitializeComponent();
}
private void frmTestPrint_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'usersDataSet1.Booking' table. You can move, or remove it, as needed.
this.bookingTableAdapter.Fill(this.usersDataSet1.Booking);
}
private void btnDelete_Click(object sender, EventArgs e)
{
dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
}
}
}
推荐答案
这只是一次删除一个.我仍在处理多个删除操作.
This is only to delete one at a time. I am still working on multiple deletes.
if (MessageBox.Show("Sure you wanna delete?", "Warning", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
//get the index from the dataGridView
int rowIndex = table1DataGridView.CurrentCell.RowIndex;
//Remove from both the actual database & datagridview
table1BindingSource.RemoveAt(rowIndex);
//update table 1
this.table1TableAdapter.Update(this.maquinasDataSet.Table1);
//load table 1
this.table1TableAdapter.Fill(this.maquinasDataSet.Table1);
}
这篇关于从 DataGridView winforms 中的数据库中删除数据行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!