We help IT Professionals succeed at work.

Set Defaultvalue on a table using ADO.

thimerion
thimerion asked
on
I really need a way to set

1*/ DefaultValue property

(2*/ DecimalPlaces property)

On my Access table using ADOX...

Please experts, look any further into this.  

Thimerion
Comment
Watch Question

CERTIFIED EXPERT

Commented:
have u tried recYourRec("YourField").DefaultValue = "TheDefaultValue"

Commented:
Hi,

You cannot set the default value of the column with ADOX, this is a bug. The following text is from msdn.microsoft.com:

SYMPTOMS
When attempting to set the Default property of an ADOX column object using the Microsoft Jet 4.0 provider, the value is not set. No error message is generated. Trying to change the Default property removes any existing Default value already in place.



RESOLUTION
To work around this problem, you can execute an ALTER TABLE command to accomplish the same functionality. For example, to add a default value to MyColumn in MyTable, use the following command:

ALTER TABLE MyTable ALTER COLUMN MyColumn SET DEFAULT 'DefaultValue'

BartonM

Author

Commented:
BartonM
And for DecimalPlaces,
is there also an SQL statement that can set them??

Tim

Author

Commented:
Thanks,
I works :-)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.