jonbinsdesu
Honorary Poster
- Joined
- May 23, 2018
- Posts
- 506
- Reaction
- 110
- Points
- 198
- Age
- 28
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
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);
}
Last edited: