Bonjour,

J´ai un bouton delete pour effacer aussi bien dans ma database comme le fichier dans le disque dur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
private void DeleteButton_Click(object sender, EventArgs e)
        {
 
            Cursor.Current = Cursors.WaitCursor;
            /////
 
            /////
            string location = Directory.GetCurrentDirectory() + @"\Saints\" + CategoriaCaballerosComboBox.Text + @"\" + NombreCaballerosTextBox.Text;
            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Saints\" + CategoriaCaballerosComboBox.Text + @"\" + NombreCaballerosTextBox.Text))
            {
                //using (var image = Image.FromFile(location))
                //{
                //    CaballeroPictureBox.Image = (Image)image.Clone();
                //}
 
                CaballeroPictureBox.Dispose();
 
                Directory.Delete(location, true);
            }
 
            SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True");
            con.Open();
            if (CaballerosDataGridView.SelectedRows.Count > 0)
            {
                int selectedIndex = CaballerosDataGridView.SelectedRows[0].Index;
                int rowID = int.Parse(CaballerosDataGridView[0, selectedIndex].Value.ToString());
                SqlCommand cmd = new SqlCommand("DELETE FROM Caballeros where Id=@id;", con);
                cmd.Parameters.AddWithValue("@id", rowID);
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("deleted");
                RefreshDataGrid();
                Cursor.Current = Cursors.Default;
            }
        }
Mais en cliquant dessus j´ai une erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
System.IO.IOException*: 'Le processus ne peut pas accéder au fichier 'x.png', car il est en cours d'utilisation par un autre processus.'
Donc comment contourner ce probleme ?
Merci