| 12
 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(); | 
Partager