Forums - C# Corner

Forum guidelines

Not able to read the image saved in database

Sep 17 2010 12:18 AM
The error is : A generic error occurred in GDI+.

i am providing u the Read button click code below:

 private void btnReadImage_Click(object sender, EventArgs e)
            if (txtBrowse.Text != "")
                String sql = "select UserPhoto, UserID, UserName,UserEmail,  UserDescription from User_info where UserID='1'";
                SqlConnection conn = new SqlConnection(@"Password=Sql2008;Persist Security Info=True;User ID=sa;Initial Catalog=anil;Data Source=SST-08\SQL2008");
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                SqlCommandBuilder cmd = new SqlCommandBuilder(da);

                DataSet ds = new DataSet("User_info");
                da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                da.Fill(ds, "User_info");
                DataRow row = ds.Tables["User_info"].Rows[0];
                byte[] rawdata = new byte[0];
                rawdata = (byte[])row["UserPhoto"];
                int len = new int();
                len = rawdata.GetUpperBound(0);
                FileStream fs = new FileStream(savedImageName, FileMode.OpenOrCreate, FileAccess.Write);
                fs.Write(rawdata, 0, len);
                curImage = Image.FromFile(savedImageName);
                pictureBox1.Image = curImage; 
                if (conn != null)
                    if (conn.State == ConnectionState.Open)

                MessageBox.Show("First upload the image ");

Answers (1)


Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now