我想使用数组从访问数据库中删除多个记录.该数组是从文件名动态加载的.
然后我查询数据库,看看数据库列值是否与数组值匹配,如果没有则删除它,如果匹配则不删除它.
问题是:以下是删除所有记录的代码,与条件中的位置无关.
arrays = Directory.GetFiles(sdira, "*", SearchOption.AllDirectories).Select(x => Path.GetFileName(x)).ToArray();
fnames.AddRange(arrays);
here I have use also for loop but that also didnt help me out :( like for(int u = 0; u < arrays.length; u++) { oledbcommand sqlcmd = new oledbcommand ("delete from table1 where name not in ("'+arrays[u]+"')",sqlconnection);
I am using this one currently foreach(string name in arrays)
{
OleDbCommand sqlcmd = new OleDbCommand("delete from table1 where name not in ('" + name + "')", sqlconnection);
sqlcmd.ExecuteNonQuery(); }`
Run Code Online (Sandbox Code Playgroud)