Im using this
this is the data type im sending in the cmd:
NpgsqlTypes.NpgsqlDbType.Real;
here im cheking that is a numeric value:
public bool IsNumeric(String value){ try{ float.Parse(value); return true; } catch(Exception e){ return false; } }
And here is the alter table:
ALTER TABLE "Medicine" ADD COLUMN "Price" real; ALTER TABLE "Medicine" ALTER COLUMN "Price" SET NOT NULL;
The table data type is Real too, thats how i can save "float" cuz it seen that PostgreSQL doesnt have a float. Ive tried with double, money, numeric, and still doesnt work. The numbers is inserted in the table, but w/o the ".", for example, i writte 12.34 and 1234 is inserted. Already checked everything when debugging.
How can i solve this?
First of all your isNumeric function is a bad way to check if a string value is numeric, this is a terrific use of try-catch construct ...
You should check if the string is numeric with a regular expression like the following :
public static bool IsNumeric(string value)
{
bool match;
//regular expression to match numeric values
string pattern = "(^[-+]?\\d+(,?\\d*)*\\.?\\d*([Ee][-+]\\d*)?$)|(^[-+]?\\d?(,?\\d*)*\\.\\d+([Ee][-+]\\d*)?$)";
Regex regEx = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
match = regEx.Match(value).Success;
return match;
}
Then to insert a REAL value into the table you should convert it into the Single .NET datatype, take a look at the table in this question answer .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With