Load Image File [Resolved]
Hi guys good day. I have this problem about loading an image that was saved from the database(convert the image file to byte then saved). When I was going to load it(convert the value to byte then use the memorystream class to convert the byte file to image file) but it throws an exception "Input string was not in a correct format".
Am I missing something here? :eek:
Here's the code:
Code:
private void button1_Click(object sender, System.EventArgs e)
{
getimage();
}
//method to get the binary value in the database
void getimage()
{
cn.Open();
SqlCommand cm=new SqlCommand("select * from sample",cn);
byte[] img={byte.Parse(cm.ExecuteScalar().ToString())};<---line that throws an error.
cn.Close();
loadimage(img);
}
//method to load the image
Image ximage;
void loadimage(byte[] img)
{
System.IO.MemoryStream im=new System.IO.MemoryStream(img);
im.Flush();
ximage=Image.FromStream(im);
im.Close();
this.pictureBox1.Image=ximage;
}
Re: Load Image File [Resolved]
Btw people, how do I upload files on another unit? Say I know the IP address. What's the prerequisite? Right now, I'm saving the byte[] to the db. Sounds not a good idea. So anyone has good links about this one? Or any code examples if you may share? Thanks a bunch.
Edit: Or do I need to post another topic for this one? Sorry for bothers.