One problem is that your code is confusing.
string [] a = {"" 'a.jpg', 'b.jpg', 'c.jpg' "}
First you have a double "in the beginning, there should be only one.
string [] a = {" 'a.jpg', 'b.jpg', 'c.jpg' "}
Then it created an array of strings with one element,
a[0] = "'a.jpg', 'b.jpg', 'c.jpg'";
Then you do foreach on this, which natuarly ony does once, leading to this query:
delete from table1 where name not in ('a.jpg', 'b.jpg', 'c.jpg')
, , ,
a[0] = 'a.jpg';
a[1] = 'b.jpg';
a[1] = 'c.jpg';
3 foreach,
delete from table1 where name not in ('a.jpg')
delete from table1 where name not in ('b.jpg')
delete from table1 where name not in ('c.jpg')
.
:
string[] names = { "a.jpg", "b.jpg","c.jpg","j.jpg" };
string allNames = "'" + String.Join("','", names) + "'";
OleDbCommand sqlcmd = new OleDbCommand("delete from table1 where name not in (" + allNames + ")", sqlconnection);
sqlcmd.ExecuteNonQuery();
- , , :
delete from table1 where name not in ('a.jpg', 'b.jpg', 'c.jpg')
, , , .
eacy, .
List<string> names = new List<string>();
var names = new List<string>();
add , .
names.Add(filename);
:
string allNames = "'" + String.Join("','", names.ToArray()) + "'";
.
string[] filePaths = Directory.GetFiles(@"c:\MyDir\", "*.jpg");
string[] names = filePaths.ToList().ConvertAll(n => n.Substring(n.LastIndexOf(@"\") + 1)).ToArray();