Click here to Skip to main content
15,881,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Bitmap ByteArrayToImage(byte[] b)
        {
            MemoryStream ms = new MemoryStream();
            byte[] pData = b;
            ms.Write(pData, 0, Convert.ToInt32(pData.Length));
            Bitmap bm = new Bitmap(ms, false);//Parameter is not valid.
             ms.Dispose();
            return bm;
        }

        int ctr = 0;
        //int len = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            da = new SqlDataAdapter("select * from Slambook_Data where serial_no=" + textBox1.Text + "", con);
            ds = new DataSet();
            da.Fill(ds, "Slambook_Data");
            ctr = ds.Tables["Slambook_Data"].Rows.Count;
            if (ds.Tables["Slambook_Data"].Rows.Count > 0)
            {
                if (ds.Tables["Slambook_Data"].Rows[0]["photo"] != DBNull.Value)
                {
                    label1.Text = ds.Tables["Slambook_Data"].Rows[0]["name"].ToString();
                    pictureBox1.Image = ByteArrayToImage((Byte[])ds.Tables["Slambook_Data"].Rows[0]["photo"]);
                }
            }
        }
Posted
Comments
PIEBALDconsult 14-Dec-13 15:00pm    
I don't know, but what the heck is this: Convert.ToInt32(pData.Length))

Simple: you wrote the wrong information to the DB in the first place.
See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^]
 
Share this answer
 
just take make one folder in your .net application and fetch from there and store only image name in database just think its very easy to access!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900