Subash P

Subash P

  • NA
  • 34
  • 13.5k

i didn't retrieve the image from Ms Access. The Error was"Parameter is not valid"..

Jan 22 2013 2:20 AM


Below i mention my coding. in this coding other fields are retrieved but the image field not retrieved. when i was double click the datagridview cell the error was come "Parameter is not valid"



private void dgvMaster_EmployeeDetails_CellDoubleClick(object sender, DataGridViewCellEventArgs e)

       {

int id = Convert.ToInt32 (dgvMaster_EmployeeDetails.Rows[e.RowIndex].Cells[0].Value);

 

            cmd.CommandText = "select * from EmployeeMaster_Table where [No]="+id;

            cmd.Connection = conn;

            conn.Open();

try

              {

                 dr = cmd.ExecuteReader();

                 while (!dr.Read().Equals(System.DBNull.Value))

                 {

                    txtMaster_EmpId.Text = dr["Employee ID"].ToString();

                    txtMaster_EmpName.Text = dr["Employee Name"].ToString();

                    txtMaster_Position.Text = dr["Designation"].ToString();

                    cbMaster_Department.Text = dr["Department"].ToString();

                    txtMaster_Email.Text = dr["E-Mail"].ToString();

                    txtMaster_PerEmail.Text = dr["Personal E-mail"].ToString();

                    txtMaster_Contact1.Text = dr["Contact No1"].ToString();

                    txtMaster_Contact2.Text = dr["Contact No2"].ToString();

                    picb_Employee.Image = ByteArrayToImage((Byte[])dr["Emp Photo"]);

 

                }

                dr.Close();

            }           

         

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message.ToString());

            }

            finally

            {

                conn.Close();

            }

}

 

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);            

            ms.Dispose();

           return bm;

 }