Last post Oct 09, 2009 02:12 AM by Wencui Qian - MSFT
Oct 05, 2009 09:13 PM|hkbeer|LINK
Hi I have an ASP.Net page with access datasource and I have successfully created a code to insert a value to a field in the records using Inserting event handler code from a textbox receiving value from user as follows. However, this field is supposed to
be a decimal (eg 3.2, 1.11 etc) but when inserted, it is inserted as 3, 1 (ie truncated all decimal places). How should I modify the code ?
I have already set field type to decimal in mdb file already for the field.
Protected Sub AccessDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)
e.Command.Parameters("Sales").Value = Val(TextBox2.Text.ToString)
Oct 05, 2009 11:12 PM|x_com|LINK
It seem like Val() function is given the unnecessary conversion for decimal type. Try to remove it and see the different. You can write own custom function to validate the numeric data that entered in this case.
Oct 09, 2009 02:12 AM|Wencui Qian - MSFT|LINK
I think you can try this way:
e.Command.Parameters("Sales").Value = decimal.Parse(TextBox2.Text.ToString);
The Parse method will convert a string to a decimal value.