本文介绍了从访问中删除多条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用一个sql语句删除多个记录,
但它不能代替删除特定记录而无法工作,而是会删除整个表:
我的代码是:
I want to delete multiple record with one sql statement,
but it is not working instead of deleting specific records it delete the whole table:
my code is:
string[] names = { "a.jpg","b.jpg","c.jpg"};
for (int j = 0; j<names.length;>
{
OleDbCommand sqlcmd = new OleDbCommand("delete from table1 where name not in (''" + names[j] + "'')", sqlconnection);
sqlcmd.Parameters.AddWithValue("name", names[j]);
sqlcmd.executenonquery();
}
我正在使用C#和Access
感谢您的帮助并阅读了问题.
祝你有美好的一天
[Edited]代码包装在"pre"标签中[/Edited]
I am using C# and Access
Thanks for your help and reading the question.
Have nice day
Code is wrapped in "pre" tags[/Edited]
推荐答案
string names = "'a.jpg', 'b.jpg', 'c.jpg'";
OleDbCommand sqlcmd = new OleDbCommand("delete from table1 where name not in (" + names + ")", sqlconnection);
sqlcmd.executenonquery();
这篇关于从访问中删除多条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!