Sim*_*zie 17
最好使用正确的列数据类型来计划存储在其中的内容,但是检查字符串是否只包含数字非常容易 - 只需解析并查看是否返回错误:
int parsedValue;
if (!int.TryParse(textBox.Text, out parsedValue))
{
MessageBox.Show("This is a number only field");
return;
}
// Save parsedValue into the database
Run Code Online (Sandbox Code Playgroud)