Link to home
Start Free TrialLog in
Avatar of nctran
nctran

asked on

TADOTable Field.Required property

When TADOTable object connected to SQL Database table. I noticed that the Field.Required and FieldDef.Required property always returns False, even though the underlying Table has field which is non Nullable.

Is it because of the MDAC version or SQL server version conflict ? I search every where on the web but could not find any one mentioned about having this problem.

I am using XP machine to connect to SQL Sever 2000 which is running in window 2000 server.

Your help will be very much appreciated.

Cheers,

nctran
Avatar of Ivanov_G
Ivanov_G
Flag of Bulgaria image


   Delphi help says :

If a field is created with the Fields editor, then this property is set based on the underlying table. Applications that set Required to True for fields that must have values (for example, a password or part number), but for which the underlying table does not require the field, must write an OnValidate event handler to enforce the property.
ASKER CERTIFIED SOLUTION
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of 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

   whenever possible - use direct access components :P)

   http://crlab.com/sdac/

   I am using them and everything is OK :)))
Avatar of nctran
nctran

ASKER


SQL database table has specified the field is required (non Nullable). But when loaded into TADOTable the field.Required property is always return false.
 
  any ideas ?

Best Regards
Hello

  Here's a better way, without modifying Delphi sources

procedure TForm1.Button1Click(Sender: TObject);
var
  ReqField : Integer;
const
  adFldIsNullable = $00000020;
begin
  if (AdoTable1.Recordset.Fields[1].attributes and adFldIsNullable) = 0 then
    ShowMessage(AdoTable1.Recordset.Fields[1].Name + ' is Required Field')
  else
    ShowMessage(AdoTable1.Recordset.Fields[1].Name + ' not Required Field')

end;

Regards,
Mohammed

    Set Debug DCU in Project / Options / Compiler / Debugging and step inside the ado units to see why it fails ...
Avatar of nctran

ASKER

Thanks Mohammed,
I knew it was a bug in ADO express but not quite sure where is a good place to fix it. Because I Trace through the code and found that the attributes never get check again adFldNullable.

It seems to work for SQL database .But I don't know if there is any problem when connected TADOTable object to any other databases and I hope not.

 I prefer to change it in the ADODB because It saves me to go everywhere in my code to change Field.Required to Recordset.Field[i].Attributes and adFldIsNullable = 0

So I  will accept your comment.

Thank you.