shah Momin

shah Momin

  • NA
  • 176
  • 22.1k

System.NullReferenceException:Object reference not set to an instances

May 30 2022 9:41 PM

This Code Working Fine  

ConfigurationBLL configurationBLL = new ConfigurationBLL();
int selectedvalue = (int)ddlVolunteerName.SelectedValue;
if (!(ddlVolunteerName.SelectedValue.ToString() != "-1"))
    return;
DataSet dataSet = configurationBLL.FetchVolunteerDetails(volunteerID:selectedvalue);
DataRow row = dataSet.Tables[0].Rows[0];
txtFirstName.Text = row["FIRSTNAME"].ToString();
txtMiddleName.Text = row["MIDDLENAME"].ToString();
txtSurname.Text = row["SURNAME"].ToString();
txtAddress.Text = row["ADDRESS"].ToString();
txtCNIC.Text = row["CNIC"].ToString();
txtHomePhoneNumber.Text = row["HOMEPHONENUMBER"].ToString();
txtMobilePhoneNumber.Text = row["MOBILEPHONENUMBER"].ToString();
txtEmailAddress.Text = row["EMAILADDRESS"].ToString();
txtAcademicQualification.Text = row["ACADEMICQUALIFICATION"].ToString();
txtAcademicQualification.Text = row["RELIGIOUSQUALIFICATION"].ToString();
txtMaritalStatus.Text = row["MARITALSTATUS"].ToString();
ddlBloodGroup.SelectedItem = (object)row["BLOODGROUP"].ToString();
txtLastTimeBloodDonated.Text = row["LASTTIMEBLOODDONATED"].ToString();
txtOccupation.Text = row["OCCUPATION"].ToString();
txtFirmName.Text = row["FIRMNAME"].ToString();
txtDesignation.Text = row["DESIGNATION"].ToString();
txtWorkAddress.Text = row["WORKADDRESS"].ToString();
ddlGroupName.SelectedValue = (object)row["GROUPNAME"].ToString();
txtDateofBirth.Text = row["DATEOFBIRTH"].ToString();
txtDateofJoining.Text = row["DATEOFJOINING"].ToString();
ddlCurrentPosition.SelectedValue = (object)row["VOLUNTEERPOSITIONID"].ToString();
txtPrevInstitutionName.Text = row["PREVINSTITUTIONNAME"].ToString();
txtPrevInstitutionJoiningDate.Text = row["PREVINSTITUTIONJOININGDATE"].ToString();
txtPrevInstitutionLeavingDate.Text = row["PREVINSTITUTIONLEAVINGDATE"].ToString();
if (row["ISMEDICALINSURANCE"].ToString() == "1")
{
    rbtnYesMedicalInsurance.Checked = true;
    rbtnNoMedicalInsurance.Checked = false;
}
else if (row["ISMEDICALINSURANCE"].ToString() == "0")
{
    rbtnYesMedicalInsurance.Checked = false;
    rbtnNoMedicalInsurance.Checked = true;
}
else
{
    rbtnYesMedicalInsurance.Checked = false;
    rbtnNoMedicalInsurance.Checked = false;
}
if (row["ISFIREFIGHTING"].ToString() == "1")
{
    rbtnYesFireFighting.Checked = true;
    rbtnNoFireFighting.Checked = false;
}
else if (row["ISFIREFIGHTING"].ToString() == "0")
{
    rbtnYesFireFighting.Checked = false;
    rbtnNoFireFighting.Checked = true;
}
else
{
    rbtnYesFireFighting.Checked = false;
    rbtnNoFireFighting.Checked = false;
}
if (row["ISFIRSTAID"].ToString() == "1")
{
    rbtnYesFirstAid.Checked = true;
    rbtnNoFirstAid.Checked = false;
}
else if (row["ISFIRSTAID"].ToString() == "0")
{
    rbtnYesFirstAid.Checked = false;
    rbtnNoFirstAid.Checked = true;
}
else
{
    rbtnYesFirstAid.Checked = false;
    rbtnNoFirstAid.Checked = false;
}
if (row["ISENGLISHLANGUAGE"].ToString() == "1")
{
    rbtnYesEnglishLanguage.Checked = true;
    rbtnNoEnglishLanguage.Checked = false;
}
else if (row["ISENGLISHLANGUAGE"].ToString() == "0")
{
    rbtnYesEnglishLanguage.Checked = false;
    rbtnNoEnglishLanguage.Checked = true;
}
else
{
    rbtnYesEnglishLanguage.Checked = false;
    rbtnNoEnglishLanguage.Checked = false;
}
if (row["ISBOMBDISPOSAL"].ToString() == "1")
{
    rbtnYesBombDisposal.Checked = true;
    rbtnNoBombDisposal.Checked = false;
}
else if (row["ISBOMBDISPOSAL"].ToString() == "0")
{
    rbtnYesBombDisposal.Checked = false;
    rbtnNoBombDisposal.Checked = true;
}
else
{
    rbtnYesBombDisposal.Checked = false;
    rbtnNoBombDisposal.Checked = false;
}
if (row["ISCERT"].ToString() == "1")
{
    rbtnYesCERT.Checked = true;
    rbtnNoCERT.Checked = false;
}
else if (row["ISCERT"].ToString() == "0")
{
    rbtnYesCERT.Checked = false;
    rbtnNoCERT.Checked = true;
}
else
{
    rbtnYesCERT.Checked = false;
    rbtnNoCERT.Checked = false;
}
if (row["ISSECURITY"].ToString() == "1")
{
    rbtnYesSecurity.Checked = true;
    rbtnNoSecurity.Checked = false;
}
else if (row["ISSECURITY"].ToString() == "0")
{
    rbtnYesSecurity.Checked = false;
    rbtnNoSecurity.Checked = true;
}
else
{
    rbtnYesSecurity.Checked = false;
    rbtnNoSecurity.Checked = false;
}
if (row["ISRESIGN"].ToString() == "0")
{
    rbtnYesActive.Checked = true;
    rbtnNotActive.Checked = false;
}
else
{
    rbtnYesActive.Checked = false;
    rbtnNotActive.Checked = true;
    txtDateofLeaving.Text = row["DATEOFLEAVING"].ToString();
}
if (row["PROFILEPHOTO"] is byte[])
{
    byte[] buffer = (byte[])row["PROFILEPHOTO"];
    MemoryStream memoryStream = new MemoryStream(buffer);
    try
    {
        picPhoto.Image = Image.FromStream((Stream)memoryStream);
        bPhotoImage = buffer;
    }
    catch (Exception ex)
    {
        picPhoto.Image = (Image)null;
    }
}
else
    picPhoto.Image = (Image)null;
DataTable table1 = dataSet.Tables[1];
FingerPrints prints = new FingerPrints();
for (int index = 0; index < table1.Rows.Count; ++index)
{
    switch (int.Parse(table1.Rows[index]["FINGERPRINTID"].ToString()))
    {
        case 11:
            if (table1.Rows[index]["FINGERPRINTPHOTO"] is byte[])
            {
                byte[] imgData = (byte[])table1.Rows[index]["FINGERPRINTPHOTO"];
                DrawImage(imgData, prints.picRightThumb);
                picRightThumbPhoto = imgData;
                bRightThumbImage = (byte[])table1.Rows[index]["FINGERPRINTTEMPLATE"];
                break;
            }
           prints.picRightThumb.Image = (Image)null;
            break;
        case 12:
            if (table1.Rows[index]["FINGERPRINTPHOTO"] is byte[])
            {
                byte[] imgData = (byte[])table1.Rows[index]["FINGERPRINTPHOTO"];
                DrawImage(imgData, prints.picRightIndex);
                picRightIndexPhoto = imgData;
                bRightIndexImage = (byte[])table1.Rows[index]["FINGERPRINTTEMPLATE"];
                break;
            }
            prints.picRightIndex.Image = (Image)null;
            break;
        case 16:
            if (table1.Rows[index]["FINGERPRINTPHOTO"] is byte[])
            {
                byte[] imgData = (byte[])table1.Rows[index]["FINGERPRINTPHOTO"];
                DrawImage(imgData, prints.picLeftThumb);
                picLeftThumbPhoto = imgData;
                bLeftThumbImage = (byte[])table1.Rows[index]["FINGERPRINTTEMPLATE"];
                break;
            }
            prints.picLeftThumb.Image = (Image)null;
            break;
        case 17:
            if (table1.Rows[index]["FINGERPRINTPHOTO"] is byte[])
            {
                byte[] imgData = (byte[])table1.Rows[index]["FINGERPRINTPHOTO"];
                DrawImage(imgData, prints.picLeftIndex);
                picLeftIndexPhoto = imgData;
                bLeftIndexImage = (byte[])table1.Rows[index]["FINGERPRINTTEMPLATE"];
            }
            else
                prints.picLeftIndex.Image = (Image)null;
            break;
    }
    //prints.Show();
}
DataTable table2 = dataSet.Tables[2];
LetterRecord letterRecord = new LetterRecord();
for (int index = 0; index < table2.Rows.Count; ++index)
{
    string str = table2.Rows[index]["LETTERIMAGEPATH"].ToString();
    imageListLetter.Images.Add(Image.FromStream((Stream)new MemoryStream((byte[])table2.Rows[index]["LETTERIMAGE"])));
    listLetter.BeginUpdate();
    listLetter.Items.Add(str);
    listLetter.EndUpdate();
}
if (table2.Rows.Count > 0)
{
    iCurrentImage = 0;
    letterRecord.txtFileName.Text = listLetter.Items[iCurrentImage].ToString();
    letterRecord.picLetter.Image = imageListLetter.Images[iCurrentImage];
    letterRecord.lblPaging.Text = (iCurrentImage + 1).ToString() + " of " + (object)listLetter.Items.Count;
    //btnPrevious.Enabled = true;
    //btnNext.Enabled = true;
}
else
    iCurrentImage = -1;
letterRecord.Show();

Line Number 221. Not Working

                imageListLetter.Images.Add(Image.FromStream((Stream)new MemoryStream((byte[])table2.Rows[index]["LETTERIMAGE"])));
 


Answers (5)