How to use validations for windows application with c#?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Muralikrishna
    New Member
    • Oct 2011
    • 21

    How to use validations for windows application with c#?

    Hi All,

    How to use validations for windows application with c#. I have kept "error provider" for two text box validation. It is showing error, But at the same time record also saving in to database.Once all the fields is field then only record will be save in to database. And how to add required validation for combo box? Please find the attached code document.

    Thanks and regards,
    Murali.
    Attached Files
  • Muralikrishna
    New Member
    • Oct 2011
    • 21

    #2
    I tried like this , it's working fine.


    Code:
    if (txtAddress.Text != "")
    {
    if (txtPincode.Text != "")
    {
     
    if (txtcity.Text != "")
    {
     
    SqlConnection con = new SqlConnection(strConn);
    con.Open();
    SqlCommand cmd = new SqlCommand("sp_rm_insert_basicfamily", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@FamilyID", txtFamilyid.Text);
    cmd.Parameters.AddWithValue("@HHID", txtHeadofhousehold.Text);
    cmd.Parameters.AddWithValue("@Religion", cbxReligion.SelectedValue);
    cmd.Parameters.AddWithValue("@Caste", cbxCaste.SelectedValue);
    cmd.Parameters.AddWithValue("@HouseNo", txtHouseno.Text);
    cmd.Parameters.AddWithValue("@Address1", txtAddress.Text);
    cmd.Parameters.AddWithValue("@Village", txtcity.Text);
    cmd.Parameters.AddWithValue("@State", cbxState.SelectedValue);
    cmd.Parameters.AddWithValue("@District", cbxDistrict.SelectedValue);
    cmd.Parameters.AddWithValue("@Mandal", cbxMandal.SelectedValue);
    cmd.Parameters.AddWithValue("@Pincode", txtPincode.Text);
    cmd.ExecuteNonQuery();
    con.Close();
    MessageBox.Show("Successfully Saved");
    }
     
    else
    {
    MessageBox.Show("Please enter city");
    }
    }
     
    else
    {
    MessageBox.Show("Please enter pin code");
    }
    }
     
    else
     
    {
     
    MessageBox.Show("Please enter address");
     
    }
    Last edited by Meetee; Dec 10 '12, 08:12 AM. Reason: Use code tags <code/> around your code

    Comment

    Working...