protected void ad3upload_Click(object sender, EventArgs e) { if (FileUpload6.HasFile) { string fileName = FileUpload6.FileName; string path = fileName; TextBox13.Text = fileName; FileUpload6.SaveAs(Server.MapPath(path)); pass3img.ImageUrl = path; //this gets admin1passport Stream fs3 = FileUpload6.PostedFile.InputStream; BinaryReader br3 = new BinaryReader(fs3); Byte[] bytes3 = br3.ReadBytes((Int32)fs3.Length); try { MySqlConnection conn = new MySqlConnection(connection); MySqlCommand ins = new MySqlCommand("update tables.admintable set Passport = @img where Name = '" + newname.Text + "'", conn); MySqlDataReader read; conn.Open(); ins.Parameters.Add("@img", MySqlDbType.Binary).Value = bytes3; read = ins.ExecuteReader(); conn.Close(); Label84.ForeColor = System.Drawing.Color.Green; Label84.Text = "Successful Upload"; } catch (MySqlException) { Label84.ForeColor = System.Drawing.Color.Red; Label84.Text = "Failed Upload, Please Try Agin"; } catch (Exception) { Label84.ForeColor = System.Drawing.Color.Red; Label84.Text = "Failed Upload, Please Try Agin"; } } } it succesfully uploads buy when i recall the image from the database through these set of codes protected void adminListBox_SelectedIndexChanged(object sender, EventArgs e) { try { MySqlConnection conn = new MySqlConnection(connection); MySqlCommand select = new MySqlCommand("select Passport from tables.admintable where Name = '" + Label33.Text + "'", conn); MySqlDataReader read; conn.Open(); read = select.ExecuteReader(); while (read.Read()) { byte[] passportImage1 = (byte[])(read["Passport"]); if (adminListBox.SelectedIndex.Equals(0)) { if (passportImage1 == null) { adminImage.ImageUrl = null; } else { MemoryStream ms = new MemoryStream(passportImage1); // this holds the image gotten from the database string base64string = Convert.ToBase64String(passportImage1, 0, passportImage1.Length); adminImage.ImageUrl = "data:image/png;base64," + base64string; } } } read.Close(); conn.Close(); catch (MySqlException) { Label84.ForeColor = System.Drawing.Color.Red; Label84.Text = "Failed Upload, Please Try Agin"; } catch (Exception) { Label84.ForeColor = System.Drawing.Color.Red; Label84.Text = "Failed Upload, Please Try Agin"; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)