Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void cmbEmpId_SelectedIndexChanged(object sender, EventArgs e)
        {
           SqlConnection ca = new SqlConnection();
           ca.ConnectionString = c1.pass();
           ca.Open();

            string str = "Select *  From EmpDetails where Emp_Id='" + cmbEmpId.Text.ToString() + "'";
            SqlCommand cam = new SqlCommand(str, ca);
            SqlDataReader sdr = cam.ExecuteReader();
           
            while (sdr.Read())
            {
                txtAddress.Text = Convert.ToString(sdr[5]);
                txtCity.Text = Convert.ToString(sdr[6]);
                cmbCountry.Text = Convert.ToString(sdr[7]);
                txtContactNo.Text = Convert.ToString(sdr[8]);
                txtEMailId.Text = Convert.ToString(sdr[9]);
                cmbQualification.Text = Convert.ToString(sdr[10]);
                cmbDesignation.Text = Convert.ToString(sdr[12]);
                cmbDepartment.Text = Convert.ToString(sdr[13]);

              
                byte[] img_arr1 = (byte[])sdr["photo"];
                MemoryStream ms = new MemoryStream();
                ms.Position = 0;
                ms.Write(img_arr1, 0, img_arr1.Length);
                pictureBox1.Image = Image.FromStream(ms);  <--- Giving Error "Parameter is not valid".

             }

        }
Posted
Updated 6-Jun-14 0:22am
v2

Hello Friends, Your Solution is Here
C#
private void cmbEmpId_SelectedIndexChanged(object sender, EventArgs e)           
{
SqlConnection ca = new SqlConnection();
ca.ConnectionString = c1.pass();
ca.Open();
 
string str = "Select * From EmpDetails where Emp_Id='" + cmbEmpId.Text.ToString() + "'";
SqlCommand cam = new SqlCommand(str, ca);
SqlDataReader sdr = cam.ExecuteReader();

while (sdr.Read())
{
txtAddress.Text = Convert.ToString(sdr[5]);
txtCity.Text = Convert.ToString(sdr[6]);
cmbCountry.Text = Convert.ToString(sdr[7]);
txtContactNo.Text = Convert.ToString(sdr[8]);
txtEMailId.Text = Convert.ToString(sdr[9]);
cmbQualification.Text = Convert.ToString(sdr[10]);
cmbDesignation.Text = Convert.ToString(sdr[12]);
cmbDepartment.Text = Convert.ToString(sdr[13]);
 

//byte[] img_arr1 = (byte[])sdr["photo"];
//MemoryStream ms = new MemoryStream();
//ms.Position = 0;
//ms.Write(img_arr1, 0, img_arr1.Length);
//pictureBox1.Image = Image.FromStream(ms); <--- Giving Error "Parameter is not valid".            

MemoryStream ms = new MemoryStream((byte[])sdr["photo"]);
pictureBox1.Image = Image.FromStream(ms);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Refresh();
 
}
 
} 
 
Share this answer
 
v3
Comments
the_singh 7-Jun-14 4:02am    
sorry boss but result is same. Parameter is not valid on "PictureBox1.Image = Image.FromStream(ms);"
the_singh 7-Jun-14 4:08am    
if there is another code to retrieve image from db please provide.
set the filemode property to create of memory stream
 
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