TypeIntialization Exception Was Unhandled...PLzzz help me...........

  • 12 years ago

    Hello,

             Can anyone  plzz solve my  prblm... Below  code is for Immigration_Details of the employee.....

     i got an Exception while running....

    Exception : TypeIntialization Exception was Unhandled...........

    But i didn't change the Form Name in this appln...

    Please help me..........

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.IO;

    namespace Immigration_Details1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            static SqlConnection cn = new SqlConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=EMP;Data Source=user");
            DataSet ds = new DataSet();
            SqlDataReader rdr;
            DataTable dt;
            DataRow dr;
            int i;
            private void Form1_Load(object sender, EventArgs e)
            {
                SqlCommand cmd = new SqlCommand("select empid,immigrationstatus,firstname,middilename,lastname from Employee_Details", cn);
                cn.Open();
                rdr = cmd.ExecuteReader();
                if (rdr.Read())
                {
                    empid_txt.Text = rdr["empid"].ToString();
                    immigrationstatus_cmb.Text = rdr["immigrationstatus"].ToString();
                    fname_txt.Text = rdr["firstname"].ToString();
                    mname_txt.Text = rdr["middilename"].ToString();
                    lname_txt.Text = rdr["lastname"].ToString();
                }

                if (immigrationstatus_cmb.SelectedIndex == 0)
                {
                    immg_groupBox1.Visible = true;
                    Nonimmg_groupBox2.Visible = false;
                    Immg_VisaDetails();
                }
                if (immigrationstatus_cmb.SelectedIndex == 1)
                {
                    Nonimmg_groupBox2.Visible = true;
                    immg_groupBox1.Visible = false;
                    NonImmg_VisaDetails();
                }
            }

            private void Immg_VisaDetails()
            {
                string q = "select receiptnumber,dateapplied,dateapproved from Immigrant_Details where greencarddetails='" + greencarddetails_cmb.SelectedIndex.ToString() + "'";
                SqlCommand cmnd = new SqlCommand(q, cn);
                SqlDataReader Rdr;
                cn.Open();
                Rdr = cmnd.ExecuteReader();
                while (Rdr.Read())
                {
                    receiptnumber_txt.Text = Rdr["receiptnumber"].ToString();
                    dateapplied_txt.Text = Rdr["dateapplied"].ToString();
                    dateapproved_txt.Text = Rdr["dateapproved"].ToString();
                }
            }

            private void NonImmg_VisaDetails()
            {
                SqlDataAdapter Sda = new SqlDataAdapter("select * from NonImmigrant_Details", cn);
                Sda.Fill(ds, "NonImmigration_Details");
                dt = ds.Tables["NonImmigration_Details"];
                dr = dt.Rows[i];
                visatype_cmb.Text = dr[0].ToString();
                visastartdate_txt.Text = dr[1].ToString();
                visaexpirationdate_txt.Text = dr[2].ToString();
            }

        }
    }

     

    Advance thnx 

     

     

     

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves” - Alan Kay