Dear Friend,
Here you have to suppress the user on key press event for not entering the character that can lead to SQL injection error for this you have to follow the following steps:-
1).
private void txtCompanyPhone_KeyPress(object sender, KeyPressEventArgs e)
{
objCommonMethods.isNumericWithHyphen(e);
}
2).
internal void isNumericWithHyphen(KeyPressEventArgs e)
{
int asciiValue = Convert.ToInt32(e.KeyChar);
if ((asciiValue >= 48 && asciiValue <= 57) || asciiValue==45 || asciiValue==127 || asciiValue==8)
return;
else
e.Handled = true;
}
Here i have given you the example of allowing only numbers in the textbox and restricting rest other characters. You just need to modify accordingly the same method by using the ascii value of the characters you want to restrict and which to allow.
I hope this will help you out. Please don't forget to mark this as your answer if it really helps you out.
Thanks