如何在 C# 中从 CSV 中删除记录?
我正在尝试从 CSV 格式的文本文件中删除记录。这是我用于读取和插入记录的代码:
OleDbConnection con = new OleDbConnection();
con.ConnectionString = constr;
con.Open();
OleDbCommand COM = new OleDbCommand();
COM.Connection = con;
COM.CommandText = "select * from shop.txt where id like '" + textBoxSearch.Text + "%'";
OleDbDataAdapter da = new OleDbDataAdapter(COM);
DataSet ds = new DataSet();
da.Fill(ds);
COM.ExecuteNonQuery();
dataGridView1.DataSource = ds.Tables[0].DefaultView;
con.Close();
但它不适用于删除。删除查询如下: delete * from shop.txt where id like
注意:调用 ExecuteNoneQuery
时发生以下异常
OleDbException: Deleting data in a like此 ISAM 不支持列表。
I'm trying to remove records from CSV formatted text file. here is my code for reading and inserting records:
OleDbConnection con = new OleDbConnection();
con.ConnectionString = constr;
con.Open();
OleDbCommand COM = new OleDbCommand();
COM.Connection = con;
COM.CommandText = "select * from shop.txt where id like '" + textBoxSearch.Text + "%'";
OleDbDataAdapter da = new OleDbDataAdapter(COM);
DataSet ds = new DataSet();
da.Fill(ds);
COM.ExecuteNonQuery();
dataGridView1.DataSource = ds.Tables[0].DefaultView;
con.Close();
But it dont work for remove. the remove query is like this: delete * from shop.txt where id like <something>
Note: when calling ExecuteNoneQuery
following exception is occurred
OleDbException: Deleting data in a liked list is not supported in this ISAM.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从文本文件中删除行并不容易 - 因此 OLE 适配器不支持它。一些选项:
DataTable
中的数据,然后将其导出到 csv 文件。Deleting rows from a textfile is not easy - so the OLE adapter doesn't support it. Some options:
DataTable
and then export it to a csv file.