如何删除datarow行 [英] How to remove datarow rows
问题描述
Hello Guys,我希望你会好起来我在这里遇到新问题我想从数据库中选择值并将数据网格视图中的值传递给数据表
问题是它工作正常但是当我添加1个或更多项以便使用新值时,前一个值也添加到数据网格视图中,其次是当我删除单个数据网格视图时,我在删除按钮上出现错误
我尝试过:
删除按钮
Hello Guys, i hope you will be fine well i am here with new issue am facing that is i want to select values from database and pass that value in data grid view to data table
the problem is it's working fine but when I add 1 or more items so with new values previous one values also added in data grid view and second is when I delete single of data grid view so,i get an error on delete button
What I have tried:
Delete button
private void button7_Click_1(object sender, System.EventArgs e)
{
foreach (DataGridViewRow item in dataGridView1.Rows)
{
if (bool.Parse(item.Cells[1].Value.ToString()))
{
con_string.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = con_string;
command.CommandText = "Delete from [Runtime] Where [Values] = " + item.Cells[0].Value.ToString() + "";
command.ExecuteNonQuery();
con_string.Close();
}
con_string.ConnectionString = @"Provider = Microsoft.ACE.OLEDB.12.0;Data Source =|DataDirectory|\Restaurant.accdb;Persist Security Info=False";
DataSet dsa = new DataSet();
DataTable dt = new DataTable();
dsa.Tables.Add(dt);
OleDbDataAdapter da = new OleDbDataAdapter();
da = new OleDbDataAdapter("SELECT * FROM [Runtime] where [column3] = '"+dineinno.ToString()+"'", con_string);
da.Fill(dt);
//dataGridView3.DataSource = dt;
foreach (DataRow item in dt.Rows)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[2].Value = item["Column3"].ToString();
dataGridView1.Rows[n].Cells[0].Value = item["Values"].ToString();
}
dt.Clear();
con_string.Close();
推荐答案
我猜您正在访问已删除且无效的数据。
我不确定,但最后一行
I guess that you are accessing a deleted and so invalid data.
I am not sure, but the last line
con_string.Close();
看起来像是关闭一个封闭的连接。
不是有错误信息吗?如何调试代码以便在一分钟内找到错误代码行和Google?
looks like a closing a closed connection.
Isnt there an error message? What about debugging your code for finding the error code-line and Google for a minute?
这篇关于如何删除datarow行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!