senad
asked on
Prevent insertion of data from a currency edit which has no value.
How can I tell my adoquery not to insert the contents of an currencyedit if it is
empty?Rightnow,when I insert (empty currencyedit) I have 0.00 ¬ written in my database.
empty?Rightnow,when I insert (empty currencyedit) I have 0.00 ¬ written in my database.
oh to be clear:
another possibility is if one of your data-aware controls is READING a null value as 0.00, such as a DBCurrencyEdit. (Or as explained, the value might not actually be Null, in which case you have to find out what's storing it as 0 instead of null)
another possibility is if one of your data-aware controls is READING a null value as 0.00, such as a DBCurrencyEdit. (Or as explained, the value might not actually be Null, in which case you have to find out what's storing it as 0 instead of null)
ASKER
I am using cxCurrencyEdit (devexpress)
and inserting
INSERT INTO Table etc. using parameters
like ...ADOQuery3.Parameters.Pa ramByName( 'a11').Val ue := cxCurrencyEdit12.Value;
in the DB it has no default value just Format:Euro;
and inserting
INSERT INTO Table etc. using parameters
like ...ADOQuery3.Parameters.Pa
in the DB it has no default value just Format:Euro;
Then it seems to me that your problem is on that line.
Rather get it to check if the value is null or empty, something like
if cxCurrencyEdit12.asstring = '' //then its null / empty
or
if length(cxCurrencyEdit12.Te xt) < 1 //then its empty
then store the value as null, e.g.
ADOQUery3.Parameters.Param ByName('a1 1').value := null;
Rather get it to check if the value is null or empty, something like
if cxCurrencyEdit12.asstring = '' //then its null / empty
or
if length(cxCurrencyEdit12.Te
then store the value as null, e.g.
ADOQUery3.Parameters.Param
ASKER
The queery is as big as it is...It would be too much work to go checking every single currencyedit.
also cxcurrencyedit has no asstring property.
also cxcurrencyedit has no asstring property.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For example, how are you inserting the value? Is it byusing a data-aware currencyedit, e.g. a DBCurrencyEdit?
Or are you inserting it programmaticaly using SQL as in INSERT INTO Table etc.
Or are you saying MyADOQuery.Insert, then MyADOQUery.Fieldbyname('Fi
Next is the database itself. You're using access. Have a look at the field in design view and check things like 'default value'
===
Generally in the world of databases, NULL is different to 0. So if you DON'T insert a value into that field, by default the value should be NULL (or empty). However, there are several things that can happen when you insert a record that could pass a value of 0. For example if the field has a default value (database-side). Or if the insert takes place using a data-aware control, where the TDBCurrencyEdit might be inserting the value of 0. A default value can also take place from a dataset instance, using persisitent fields.
Hope that helps