1
Answer

How to Validate only Currency in datatable column asp.net c#

Raja

Raja

8y
335
1
int value1;
float value2;
if (int.TryParse(ds.Tables[s].Rows[i][Columncountvalue + 9].ToString(), out value1) || !float.TryParse(ds.Tables[s].Rows[i][Columncountvalue + 9].ToString().Trim(), out value2))
{
  if (value1 <= 0)
{
//Alert message
}
}
validate the currency column have only numbers. now the problem is if the value is (12,000 ) in this format statement is executed and show the alert message.how solve this issue.now how to validate the currency.
Answers (1)
1
Amit Gupta

Amit Gupta

NA 16.5k 25.6k 8y
If the database column is type of string then it recommend you to change the datatype to decimal, it will help you in future and many more queries.
 
However, if currency contains ,(comma) and you need to validate that by using the replace method
 
String cur ="12,000";
var value = Convert.ToDecimal (curr.Replace (",", "");
 
// now value contains only numbers without and seperator