Your code looks valid at a glance. When you call the ExecuteNonQuery, take the return value into a variable. So modify your code to
...
int rowsaffected = command1.ExecuteNonQuery();
...
Now using debugger, check what is the value of
rowsaffected
. It should be the total amount of rows.
If that's true then you're actually deleting all of the rows so the next question in that case would be, do you copy the mdf file as part of your application to the directory
D:\New Code\
? For example is the mdf file part of your project and defined to be copied to the output directory when you compile the app? If that is the case, then you actually 'reset' the database every time you compile and that could be the reason why the modification is 'lost'.
Also note the answer from Mark Nischalke. It's better to use
TRUNCATE
, but make that modification after you have tested how many rows are actually deleted using the
DELETE
statement.