Buonjour,

je fais une simple operation UPDATE une table qui contient un objet OLE (image), j'ai un gridview, voici mon code:

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
36
37
38
39
40
41
42
43
44
 
//Declare variable to keep file name 
        string fname = string.Empty;
 
        //Declare one variable to assign image bytes after convert
        byte[] FileBytes = null;
 
        //First save the image in the server path to get full path
 
        GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
        Label lbl = (Label)row.FindControl("lblid");
        TextBox textbox1 = (TextBox)row.FindControl("textbox1");
        TextBox textbox2 = (TextBox)row.FindControl("textbox2");
        TextBox textbox3 = (TextBox)row.FindControl("textbox3");
        FileUpload FileUpload1 = (FileUpload)row.FindControl("FileUpload2");
        GridView1.EditIndex = -1;
        if (FileUpload1.HasFile)
        {
            fname = FileUpload1.FileName;
            Stream fs = default(Stream);
            fs = FileUpload1.PostedFile.InputStream;
            BinaryReader br = new BinaryReader(fs);
            FileBytes = br.ReadBytes(FileUpload1.PostedFile.ContentLength);
            fs.Close();
            fs.Dispose();
            br.Close();
        }
        else
        {
 
        }
        conn.Open();
        string query = "UPDATE [Prodotti] SET Codice=?,Nome=?,Descrizione=?,[Image]=? where ID=" + lbl.Text + "";
        OleDbCommand cmd = new OleDbCommand(query, conn);
        cmd.Parameters.AddWithValue("@Codice", textbox1.Text);
        cmd.Parameters.AddWithValue("@Nome", textbox2.Text);
        cmd.Parameters.AddWithValue("@Descrizione", textbox3.Text);
        cmd.Parameters.AddWithValue("@Image", FileBytes);
        try
        {
            cmd.ExecuteNonQuery();
        }
        catch { };
        conn.Close();
j'affiche mon image dans le gridview a l'aide HTTPhandler, voici mon code:
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
 
 OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["SQLCONN"].ToString());
        try
        {
            int _imageId;
            if (context.Request.QueryString["id"] != null)
                _imageId = Convert.ToInt32(context.Request.QueryString["id"]);
            else
                throw new ArgumentException("No parameter specified");
 
            con.Open();
            OleDbCommand cmd = new OleDbCommand("SELECT Image FROM Prodotti where ID=" + _imageId, con);
            OleDbDataReader dr = cmd.ExecuteReader();
            dr.Read();
            context.Response.BinaryWrite((Byte[])dr[0]);
            context.Response.End();
            dr.Close();
            dr.Dispose();
            con.Close();
        }
        catch
        {
 
        }
quand je clique sur update, donne une erreur: cannot access the file because it is being used by another process
j'ai fait touts les essais mais sans resultats.

Si j'elimine le champ image, le code fonctionne tres bien.