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?![]()
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; }




Reply With Quote