Link to home
Start Free TrialLog in
Avatar of senad
senadFlag for Slovenia

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.
Avatar of rfwoolf
rfwoolf
Flag of South Africa image

There are a few issues at play here.
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('FieldName').value := Currencyedit.value;
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  
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)
Avatar of senad

ASKER

I am using cxCurrencyEdit (devexpress)
and inserting
INSERT INTO Table etc. using parameters
like ...ADOQuery3.Parameters.ParamByName('a11').Value := cxCurrencyEdit12.Value;
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.Text) < 1 //then its empty
then store the value as null, e.g.
 ADOQUery3.Parameters.ParamByName('a11').value := null;
Avatar of senad

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.
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial