-3

This is the part that I start taking data from text boxes but I want to chek it datatype at 1st
Ex: in text box 4 if the text box has letters in it show message "Error please enter Numbers only " Ex: in text box number 1 if the text box has numbers in it>> show error message" Error please enter Letters only" and so on

private void button4_Click(object sender, EventArgs e)
{

    dr = ds.Tables["Employees"].NewRow();
    dr["Name"] = textBox1.Text;           
    dr["E-Mail"] = textBox2.Text;
    dr["Age"] = textBox4.Text;
    dr["WorkHours"] = textBox5.Text;
    dr["Gender"] = textBox6.Text;
    dr["JobTitle"] = textBox3.Text;
    ds.Tables["Employees"].Rows.Add(dr);
    using (var sw = new StreamWriter("Data.xml"))
    {
        ds.WriteXml(sw);
        sw.Close();
    }

}
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
Ahmed Samy
  • 21
  • 6
  • You would have received a quicker response by searching C# data validation textbox in google: https://msdn.microsoft.com/en-us/library/ms229603(v=vs.110).aspx – Sorceri May 31 '17 at 20:46
  • I'd add that in many cases where you think you want alpha only, you actually should allow alphanumeric input. For example, in Name, you should allow "Se7en" (in case someone was named after the rapper), or "John Smith 2nd", or "La-a" (pronounced Ladasha). – hatchet - done with SOverflow May 31 '17 at 20:52

1 Answers1

0

You probably want to use int.TryParse(string, int) like

     int number;
     bool result = Int32.TryParse(textbox4.Text, out number);
Rahul
  • 76,197
  • 13
  • 71
  • 125