mardi 7 novembre 2017

Else-If Statement taking one value only based on condition

I'm currently working on comparing the selected item from a drop down list to some strings as conditions to store respected values in my database table.

However, when I used an if-else statement with my conditions, the only thing being stored is the last "else"'s value for some reason and that is the "5" only.

Here is my code:

        String command = "INSERT into customers values(@Fname,@Lname, 
        @Email, @DOB, @password, @package , @MobileNum)";
        SqlCommand com = new SqlCommand(command, con);

        com.Parameters.AddWithValue("@Fname", fnameBox.Text);
        com.Parameters.AddWithValue("@Lname", lnameBox.Text);
        com.Parameters.AddWithValue("@Email", emailBox.Text);
        com.Parameters.AddWithValue("@DOB", dobBox.Text);
        com.Parameters.AddWithValue("@password", passwordBox.Text);

      if (packageList.SelectedValue.Equals("Select"))
        {

        }
       else if (packageList.SelectedValue.Equals("1 Month"))
        {
          //  val = 1;
            com.Parameters.AddWithValue("@package", 1);
        }
        else if (packageList.SelectedValue.Equals("3 Months"))
        {
            //val = 2;
            com.Parameters.AddWithValue("@package", 2);
        }
        else if (packageList.SelectedValue.Equals("6 Months"))
        {
           // val = 4;
            com.Parameters.AddWithValue("@package", 4);
        }
        else
        {
           // val = 5;
            com.Parameters.AddWithValue("@package", 5);
        }


        com.Parameters.AddWithValue("@MobileNum", numBox.Text);

        com.ExecuteNonQuery();

Aucun commentaire:

Enregistrer un commentaire