title: Three-tier architecture implementation in Windows form application
body: <p>I am trying to insert data into a database using a three-tier architecture, but I am stuck and I cannot proceed further.</p>
  
  <p>This is my code</p>
  
  <p><strong>First is UI part:</strong></p>
  
  <pre><code>    public void assignField()
      {
          string maritalCondition = "";
          string sex = "";
  
          assignObj.Registered_Date = dateTimePicker1_Date.Value;
          assignObj.First_Name = txt_FirstName.Text;
  
          if (comboBox2_MaritalStatus.SelectedIndex == 0)
          {
              maritalCondition = "Single";
          }
          else
              maritalCondition = "Married";
  
          assignObj.Marital_Status = maritalCondition;
  
          if (RadioButton_Male.Checked == true)
              sex = "Male";
          else
              sex = "Female";
          assignObj.Gender = sex;
  
          this.txt_Age.Text = Convert.ToInt32(age).ToString();
      }
  
      private void btnRegister_Click(object sender, EventArgs e)
      {
          assignField();
      }
  </code></pre>
  
  <p>Next is the middle tier:</p>
  
  <pre><code>public class CustomerDataType
  {
      private DateTime registered_Date;
      private string first_Name;
      private int age;
      private string marital_Status;
      private string gender;
  
      public DateTime Registered_Date
      {
          get { return registered_Date; }
          set { registered_Date = value; }
      }
  
      public string First_Name
      {
          get { return first_Name; }
          set { first_Name = value; }
      }
  
      public int Age
      {
          get { return age; }
          set { age = value; }
      }
  
      public string Marital_Status
      {
          get { return marital_Status; }
          set { marital_Status = value; }
      }
  
      public string Gender
      {
          get { return gender; }
          set { gender = value; }
      }
  
      public void insertInfo()
      {
          CustomerDataAccess insertObj = new CustomerDataAccess(Registered_Date, First_Name, Age, Marital_Status, Gender);
  
          insertObj.insertCustomerInfo();
      }
  }
  </code></pre>
  
  <p>and last is the data access tier:</p>
  
  <pre><code>public class CustomerDataAccess
  {
      public CustomerDataAccess(DateTime Registered_Date, string First_Name, int Age, string Marital_Status, string Gender)
      {
          this.registrationDate = Registered_Date;
          this.fName = First_Name;
          this.userAge = Age;
          this.marriageStatus = Marital_Status;
          this.userGender = Gender;
      }
  
      SqlConnection con;
      SqlCommand cmd;
  
      DateTime registrationDate;
      string fName = "";        
      int userAge;
      string marriageStatus;
      string userGender;
  
      public void insertCustomerInfo()
      {
           try
           {  
              con = new SqlConnection("Data Source=LAKHE-PC;Initial Catalog=Sahakari;Integrated Security=True");
              con.Open();
              cmd = con.CreateCommand();
              cmd.CommandText = "sp_registerCust";
              cmd.CommandType = CommandType.StoredProcedure;
  
              cmd.Parameters.Add("@Registered_Date", SqlDbType.DateTime);
              cmd.Parameters["@Registered_Date"].Value = registrationDate;
              cmd.Parameters.Add("@First_Name", SqlDbType.VarChar);
              cmd.Parameters["@First_Name"].Value = fName;
              cmd.Parameters.Add("@Age", SqlDbType.Int.ToString());
              cmd.Parameters["@Age"].Value = userAge;
              cmd.Parameters.Add("@Marital_Status", SqlDbType.VarChar);
              cmd.Parameters["@Marital_Status"].Value = marriageStatus;
              cmd.Parameters.Add("@Gender", SqlDbType.VarChar);
              cmd.Parameters["@Gender"].Value = userGender;
  
              cmd.ExecuteNonQuery();
              con.Close();
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
  }
  </code></pre>
  
  <p>Here with the stored procedure, there is no problem and and from SQL Server I can insert data into table easily. But from windows form, it does not insert data in table. Plz help me.</p>