Mahmoud Alyan

Mahmoud Alyan

  • NA
  • 10
  • 15.2k

if condition syntax

Feb 19 2011 11:27 AM
Can anyone explain to me how to use impeded If statement (if inside if) and how to use the parentheses{}, when to use it and when not to use it, as I have tried a code with some conditions but I noticed that some times it doesn't work because of the (if and the parentheses), I'm really so confused, here is the code that worked with me but still I need to put some other conditions:
try
            {
                if (textBox7.Text == "" || textBox8.Text == "" || textBox9.Text == "" || textBox10.Text == "" || textBox11.Text == "")
                {

                    MessageBox.Show("Please make sure that the first 5 fields are not empty");

                }
                else
                {

                    //if (MessageBox.Show("Are you sure you want to update recrod??", "Confirm Exit", MessageBoxButtons.YesNo, 
                    // MessageBoxIcon.Information) != DialogResult.Yes)
                    //{
                        cmd = new SqlCommand("Update_Data_SP", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@LaptopID", textBox7.Text.Trim());
                        cmd.Parameters.AddWithValue("@StudentID", textBox8.Text.Trim());
                        cmd.Parameters.AddWithValue("@Manufacturer", textBox9.Text.Trim());
                        cmd.Parameters.AddWithValue("@Model", textBox10.Text.Trim());
                        cmd.Parameters.AddWithValue("@AcquistionYear", textBox11.Text.Trim());
                        cmd.Parameters.AddWithValue("@History", richTextBox3.Text.Trim());
                        cmd.Parameters.AddWithValue("@Comments", richTextBox4.Text.Trim());
                        con.Open();
                        int n = cmd.ExecuteNonQuery();
                        if (n > 0)
                        {
                            MessageBox.Show("Record Updated");
                            con.Close();
                        }
                            //should put here else if to check if the checkbox ticked to update the primary
                            //key with another stored procedure (Where StudentID=@StudentID)
                        else
                            MessageBox.Show("Record Not Updated");
                            con.Close();
                        //textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; textBox9.Text = ""; textBox10.Text = ""; textBox11.Text = ""; richTextBox3.Text = ""; richTextBox4.Text = "";
                    //} 
                        //else
                      
                        //    MessageBox.Show("Record Not Updated");
                        //    con.Close();                                         
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }

            finally
            {
                if (con.State == ConnectionState.Open)
                    con.Close();
            }

Answers (1)