Hyphenated numeric string saving as a negative number
Hyphenated numeric string saving as a negative number
I've inherited a database with a table that has a numeric primary key and a more... user friendly?... hyphenated numeric string (column datatype varchar). The latter is generally in the format of something like '418013-'.
In Editor, this value is getting saved with the hyphen prefixing the numeric portion of the string like so: '-418013'.
I'm guessing this value is being interpreted as a number and I need to explicitly type the value as a string, but I'm not sure where/how to do that. I've tried telling Editor not to bother saving that value at all (i.e. to not do a full row update, only changed values update), but the issue persists (I'm guessing because this hyphenated number value is being interpreted as changed somewhere early on?).
Many thanks in advance for help on this.
This question has an accepted answers - jump to answer
Answers
Have a look at the Network panel in your browser and inspect the Ajax request that is used for the edit. Specifically look at the data that is being submitted to the server from the form (this is in the "Headers" section). That will show what Editor is sending - can you let me know what it is? That will narrow the problem down a bit.
With a hyphen at the end of a number DataTables and Editor should just be treating it as a regular number. Are you able to give me a link to the page showing the issue?
Allan
Hi Allan,
As an example, the 'Form Data' information from the Network->Headers panel for a record with the original value of '90194-' is showing as this:
data[row_777][Projects][PrjNumber]: 90194-
On pressing the update button, without having made any changes to the record whatsoever, the refreshed DataTable presents the value as this: '-90194', and the field's value has also updated to '-90194' in the database.
Also, looks like this happens in any text field taking user input: if I enter the 'string' 123456-, it returns as '-123456', but if I enter '123456- abc', it returns the same as '123456- abc'. Tested this way with an editor instance having a field typed as 'text area' (e.g. fields: [{type: "textarea" ....).
I'm managing other applications (C#, Access) that save these same data to our database, and have not encountered this issue with those, but could this be something un-associated with Editor I wonder?
Unfortunately, I am unable to link you to an example.
-jorm
If that is what is being submitted to the server, then I don't believe that it is a client-side issue. Rather there is something odd going on in the server-side libraries. Are you using the Editor .NET libraries? Can you show me the code that you are using if so?
It would be worth adding
.Debug( true )
immediately before the.Process( ... )
call. That will show SQL debugging information in the JSON return from the server after an edit. Can you show me that return?Thanks,
Allan
Hi Allan,
Here's info from implementation of Debug(true), showing what I believe is the relevant bit (that the binding value is transformed to a prefixed-hyphen number - hopefully this is what you were looking for):
Then from debug there's a subsequent 'Update' statement:
I am using the following libraries from Editor 1.7.4 (in addition to DataTables 1.10.16 libraries):
The code for the problem column is pretty straightforward:
I've just been digging around with this and I believe the issue is caused by the type conversion from when the data comes in from the client-side. The type conversion function is:
The
Convert.ToInt32()
andConvert.ToDecimal()
both take the "123456-" input as a negative number! Hence why it is changed.To fix, in the "Numeric looking data" part above change the condition to be:
Thanks,
Allan
Allan,
That fixed it!
Many thanks, as always,
-jorm