By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,899 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,899 IT Pros & Developers. It's quick & easy.

How to use validations for windows application with c#?

P: 21
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
File Type: docx Validations.docx (16.3 KB, 409 views)
Dec 10 '12 #1
Share this Question
Share on Google+
1 Reply


P: 21
I tried like this , it's working fine.


Expand|Select|Wrap|Line Numbers
  1. if (txtAddress.Text != "")
  2. {
  3. if (txtPincode.Text != "")
  4. {
  5.  
  6. if (txtcity.Text != "")
  7. {
  8.  
  9. SqlConnection con = new SqlConnection(strConn);
  10. con.Open();
  11. SqlCommand cmd = new SqlCommand("sp_rm_insert_basicfamily", con);
  12. cmd.CommandType = CommandType.StoredProcedure;
  13. cmd.Parameters.AddWithValue("@FamilyID", txtFamilyid.Text);
  14. cmd.Parameters.AddWithValue("@HHID", txtHeadofhousehold.Text);
  15. cmd.Parameters.AddWithValue("@Religion", cbxReligion.SelectedValue);
  16. cmd.Parameters.AddWithValue("@Caste", cbxCaste.SelectedValue);
  17. cmd.Parameters.AddWithValue("@HouseNo", txtHouseno.Text);
  18. cmd.Parameters.AddWithValue("@Address1", txtAddress.Text);
  19. cmd.Parameters.AddWithValue("@Village", txtcity.Text);
  20. cmd.Parameters.AddWithValue("@State", cbxState.SelectedValue);
  21. cmd.Parameters.AddWithValue("@District", cbxDistrict.SelectedValue);
  22. cmd.Parameters.AddWithValue("@Mandal", cbxMandal.SelectedValue);
  23. cmd.Parameters.AddWithValue("@Pincode", txtPincode.Text);
  24. cmd.ExecuteNonQuery();
  25. con.Close();
  26. MessageBox.Show("Successfully Saved");
  27. }
  28.  
  29. else
  30. {
  31. MessageBox.Show("Please enter city");
  32. }
  33. }
  34.  
  35. else
  36. {
  37. MessageBox.Show("Please enter pin code");
  38. }
  39. }
  40.  
  41. else
  42.  
  43. {
  44.  
  45. MessageBox.Show("Please enter address");
  46.  
  47. }
Dec 10 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.