🔒 Closed Pahelp naman mga master sa code ko

Status
Not open for further replies.

jonbinsdesu

Honorary Poster
Meron akong button for update all is well and functioning may problema lang ako sa validation of existing records so yung record natin for example is
JUAN DELA CRUZ AND ANG DETAILS NIYA IS MALE, CHRISTIAN, SINGLE, juandelacruz@gmail.com, 09668066666 pag may ie-edit ako sa isa sa mga details niya di ako nakakapag save kasi participant already exist pero pag yung name ang iniba ko for update na uupdate siya. eto ang code ko

C#:
try

 {

                if (rdMale.Checked)

                {

                    gndrval = "Male";

                }else if (rdFemale.Checked)

                {

                    gndrval = "Female";

                }





                string gndr = gndrval;

                string dob = dtpDOB.Value.ToString("yyyy-MM-dd");

                string pattern = @"^.([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";

                if (txtMobileNo.TextLength != 11)

                {

                    MessageBox.Show("Please enter a valid phone number", "Add Participant", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }

                else if ((txtFirstName.Text == "") || (txtLName.Text == "") || (txtMobileNo.Text == "") || (txtEmail.Text == "") || (txtReligion.Text == ""))

                {

                    MessageBox.Show("Empty fields required", "Add Participant", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }

                else if (Regex.IsMatch(txtEmail.Text, pattern))

                {

                    int i = 0;

                    connect.closeConnection();

                    connect.openConnection();

                    cm = new MySqlCommand("SELECT * FROM tbl_participants WHERE firstname ='"+ txtFirstName.Text.Trim() +"' and middlename ='"+txtMName.Text.Trim() +"' and lastname ='"+txtLName.Text.Trim()+"'", connect.getconnection);

                    dr = cm.ExecuteReader();

                    while (dr.Read()){i++; }

                    if (i > 0)

                    {

                      

                        MessageBox.Show("Participant Already Exist", "Add Participant", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    }

                    else

                    {

                        connect.closeConnection();

                        connect.openConnection();

                        cm = new MySqlCommand("UPDATE tbl_participants SET firstname ='" + txtFirstName.Text + "', middlename ='" + txtMName.Text + "' ,  lastname ='" + txtLName.Text + "',  date_of_birth='" + dob + "',  gender='" + gndr

                            + "' ,  civil_status='" + cmbCivilStatus.Text + "' ,  religion ='" + txtReligion.Text + "',  mobileno ='" + txtMobileNo.Text + "',  emailaddress='" + txtEmail.Text + "' WHERE participants_id like'" + txtParticipantId.Text + "'", connect.getconnection);

                        cm.ExecuteNonQuery();

                        connect.closeConnection();

                        MessageBox.Show("Participant's record has been successfully updated", "Update Participant", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        LoadParticipants();

                        clear();

                    }

                  

                    }





    

                else

                {

                    MessageBox.Show("Please enter a valid email address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }

           

            }

            catch (Exception ex)

            {

                connect.closeConnection();

                MessageBox.Show("Warning: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            }
 
Ayusin mo pag post ng code.

1628822506799.webp
 
Yung radio button mo ba, male and female lang?
pwde mong gawing ganito
bale automatic female ang gender kapag di nakacheck yung male button

C#:
string gndr = rdMale.Checked ? "Male" : "Female";
 
Yung radio button mo ba, male and female lang?
pwde mong gawing ganito
bale automatic female ang gender kapag di nakacheck yung male button

C#:
string gndr = rdMale.Checked ? "Male" : "Female";
ginamit ko nayan dati boss pero nagkapalya kasi laging male ang nasesave
 
boss try mo ito boss


Code:
if (i = 0)

                    {

                      

                        MessageBox.Show("Participant Does not Exist!", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    }

                    else

                    {

                        connect.closeConnection();

                        connect.openConnection();

                        cm = new MySqlCommand("UPDATE tbl_participants SET firstname ='" + txtFirstName.Text + "', middlename ='" + txtMName.Text + "' ,  lastname ='" + txtLName.Text + "',  date_of_birth='" + dob + "',  gender='" + gndr

                            + "' ,  civil_status='" + cmbCivilStatus.Text + "' ,  religion ='" + txtReligion.Text + "',  mobileno ='" + txtMobileNo.Text + "',  emailaddress='" + txtEmail.Text + "' WHERE participants_id like'" + txtParticipantId.Text + "'", connect.getconnection);

                        cm.ExecuteNonQuery();

                        connect.closeConnection();

                        MessageBox.Show("Participant's record has been successfully updated", "Update Participant", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        LoadParticipants();

                        clear();

                    }
 
sige po bossing maraming salamat po
boss try mo ito boss


Code:
if (i = 0)

                    {

                    

                        MessageBox.Show("Participant Does not Exist!", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    }

                    else

                    {

                        connect.closeConnection();

                        connect.openConnection();

                        cm = new MySqlCommand("UPDATE tbl_participants SET firstname ='" + txtFirstName.Text + "', middlename ='" + txtMName.Text + "' ,  lastname ='" + txtLName.Text + "',  date_of_birth='" + dob + "',  gender='" + gndr

                            + "' ,  civil_status='" + cmbCivilStatus.Text + "' ,  religion ='" + txtReligion.Text + "',  mobileno ='" + txtMobileNo.Text + "',  emailaddress='" + txtEmail.Text + "' WHERE participants_id like'" + txtParticipantId.Text + "'", connect.getconnection);

                        cm.ExecuteNonQuery();

                        connect.closeConnection();

                        MessageBox.Show("Participant's record has been successfully updated", "Update Participant", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        LoadParticipants();

                        clear();

                    }
 
Status
Not open for further replies.

About this Thread

  • 12
    Replies
  • 696
    Views
  • 4
    Participants
Last reply from:
jonbinsdesu

Online now

Members online
423
Guests online
1,707
Total visitors
2,130

Forum statistics

Threads
2,275,507
Posts
28,963,744
Members
1,232,820
Latest member
bababozooo67
Back
Top