What is the easiest way to validate textboxes that need to be checked before they go through. I have 2 tables I have to insert my data into as well and that's just for one group, in total I have 3 groups but just a helpful tip towards the one will be fine.
I have the main table which is 'Person' and then 3 sub tables; 'Student', 'Teacher', 'Administration'.
Not all the textboxes need to be validated. (These two don't need to be validated sAdd2.Text and StudentType.Text).
//Edited
I'm now getting an error message with the "var pid = personTableAdapter..." with the var pid. "Embedded statement cannot be a declaration or labeled statement". Is this a decent way of trying to validate before it goes through to the database?
My normal code is
string errorMessage = "";
bool cancel = false;
if (string.IsNullOrEmpty(this.sFirstName.Text) || string.IsNullOrEmpty(this.sSurname.Text) || string.IsNullOrEmpty(this.sPhone.Text) || string.IsNullOrEmpty(this.sAdd1.Text) || string.IsNullOrEmpty(this.sSuburb.Text) || string.IsNullOrEmpty(this.sState.Text) || string.IsNullOrEmpty(this.sPostcode.Text));
if (cancel == true)
this.errorProvider1.SetError(sFirstName, "You must provide your first name");
errorMessage += "Enter your First name" + "/r/n";
this.errorProvider1.SetError(sSurname, "You must provide your surname");
errorMessage += "Enter your Surname" + "/r/n";
this.errorProvider1.SetError(sPhone, "You must provide your phone number");
errorMessage += "Enter your Phone number" + "/r/n";
this.errorProvider1.SetError(sAdd1, "You must provide your address");
errorMessage += "Enter your Address" + "/r/n";
this.errorProvider1.SetError(sSuburb, "You must provide your suburb");
errorMessage += "Enter your Suburb" + "/r/n";
this.errorProvider1.SetError(sState, "You must provide your state");
errorMessage += "Enter your State" + "/r/n";
this.errorProvider1.SetError(sPostcode, "You must provide your postcode");
errorMessage += "Enter your Postcode" + "/r/n";
if (cancel == false)
var pid = personTableAdapter.InsertPerson(sFirstName.Text, sSurname.Text, Convert.ToDateTime(sDoB.Text), sPhone.Text, sAdd1.Text, sAdd2.Text, sSuburb.Text, sState.Text, sPostcode.Text, StudentType.Text);
studentTableAdapter.Insert(Convert.ToInt32(pid), Convert.ToDateTime(sSDate.Text), sQCode.Text);
MessageBox.Show(sFirstName.Text + " " + sSurname.Text + " has been added. The Student ID is " + pid);
this.personTableAdapter.Fill(this._30002195DataSet.Person);
this.studentTableAdapter.Fill(this._30002195DataSet.Student);
this.Hide();
Admin f1 = new Admin();
f1.Show();
Thanks for your help! :)