I’m trying to use LinqToSql in Visual Studio 2010(Asp.net, C#).
The insert/delete/update records works just fine but if I write letters in a int field, the program breaks in a non-pretty way.
In my DataClasses.Designer I have:
partial void Insertproduct(product instance);
and I add other class with:
public partial class product
{
partial void OnPriceChanging(string value)
{
Regex Price = new Regex("^[A-Z0-9 a-z]*$");
if (Precio.IsMatch(value) == false)
{
throw new Exception("Just numbers");
}
}
}
I don’t know what I’m missing.
Use int.TryParse it will return a 0 if the string cannot be converted to an int.