Click here to Skip to main content
15,902,445 members

Comments by aaaaaaaaaaa222 (Top 11 by date)

aaaaaaaaaaa222 24-Sep-17 4:29am View    
I am now able to do inset but cant load the image back. what do you think I should do? thanks

private void buttonsave_Click(object sender, EventArgs e)
{
Image myImage = pictureBox1.Image;
byte[] data;
using (MemoryStream ms = new MemoryStream())
{
myImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
data = ms.ToArray();
}

con.Open();
cmd = new SqlCommand("INSERT INTO table1(id,picture) VALUES (@id,@image)", con);
{
cmd.Parameters.AddWithValue("@image", data);
cmd.Parameters.AddWithValue("@id", textBox1.Text);
cmd.ExecuteNonQuery();
}
con.Close();
}

private void buttonbrowseimage_Click(object sender, EventArgs e)
{
// open file dialog
OpenFileDialog open = new OpenFileDialog();
// image filters
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
// display image in picture box
pictureBox1.Image = new Bitmap(open.FileName);
}
}

private void buttonloadview_Click(object sender, EventArgs e)
{
cmd = new SqlCommand("SELECT picture FROM table1 WHERE id=@ID", con);
con.Open();
cmd.Parameters.AddWithValue("@ID", textBox1.Text);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
byte[] data = (byte[])reader["Picture"];
using (MemoryStream stream = new MemoryStream(data))
{
Image myImage = pictureBox1.Image;
myImage = new Bitmap(stream);
}
}
con.Close();
}
aaaaaaaaaaa222 23-Sep-17 8:27am View    
and also that isn't my connection it was 88388132's and believe me my user might not be the best way but it is better compared to 88388132's. thank you for the advise.
aaaaaaaaaaa222 23-Sep-17 8:23am View    
I've been using parameterized queries ever since I started using sql with c# and I thank you for that cause your one of the reasons why I do. Continue helping others know what's the right thing to do. thank you for the reminder.
aaaaaaaaaaa222 23-Sep-17 8:21am View    
that article's comment section isn't responsive anymore. It was dated years back, and I don't think I'll be able to receive answers from that comment section.
aaaaaaaaaaa222 23-Sep-17 8:16am View    
The codes above are from 88388132 - @User-9325517's article. I've read and saw a lot of your and other's comments helping others even before, so I do use parameterized queries. It just that the above code isn't parameterized by the creator. btw the link you commented helps. thankyou very much! :D