Click here to Skip to main content
15,881,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using ACEDAO in VC++, I am trying to retrieve the field details of an Access database (.accdb file) table of which one field is of decimal type. I am able to get the details using the functions of
C++
DAO::_FieldPtr field;
as follows:

C++
			fieldName = field->GetName().GetBSTR();
			nType = field->GetType()   // returns DAO::dbDecimal
			lSize = field->GetSize();  // returns 16
			lAttr = field->GetAttributes();  // returns 0x000002H
			nOrdinal = field->GetOrdinalPosition(); // returns 11
			bAutoIncrement = ((lAttr & DAO::dbAutoIncrField) > 0);

DAO::PropertiesPtr props;
DAO::PropertyPtr prop;
int k, nProp;
std::wstring propName, propNames;

props = field->GetProperties();

if(props)
{
	nProp = props->GetCount();  // returns 33
        for(k = 0; k < nProp; k++)
        {
            prop = field->GetProperties()->GetItem((short) k);
	    if(prop)
	    {
		propName = prop->GetName().GetBSTR();
                propNames += propName;
                propNames += L"\n";
            }
        }

        // After exiting the loop, propNames contain 33 properties as:
	//	Value
	//	Attributes
	//	CollatingOrder
	//	Type
	//	Name
	//	OrdinalPosition
	//	Size
	//	SourceField
	//	SourceTable
	//	ValidateOnSet
	//	DataUpdatable
	//	ForeignName
	//	DefaultValue
	//	ValidationRule
	//	ValidationText
	//	Required
	//	AllowZeroLength
	//	AppendOnly
	//	Expression
	//	FieldSize
	//	OriginalValue
	//	VisibleValue
	//	GUID
	//	ColumnWidth
	//	ColumnOrder
	//	ColumnHidden
	//	Description
	//	DecimalPlaces
	//	DisplayControl
	//	TextAlign
	//	AggregateType
	//	ResultType
	//	CurrencyLCID
        //      But does not have any property named "Scale" or "Precision"
}


I could not find any function for retrieving the value for precision and scale for the decimal field.

Though I am able to retrieve the field value as a decimal number and get the required information from the structure, I think it is not the right way. Because, what will happen if the data for field is not available in the table?

Is there any other method to retrieve the precision and scale of a decimal type field using ACEDAO?

Thanks.
Posted
Updated 25-Apr-15 21:07pm
v2
Comments
KarstenK 26-Apr-15 5:10am    
Try to you get the value as string, or multiplied by 1000.
pani68 26-Apr-15 5:26am    
Thanks for the comment. BTW my objective is not to retrieve the value, which can be done in many different ways. I need to determine the total number of digits and maximum number of digits after the decimal. Again, these values are to be determined from the field properties. Because, if the field is nullable, none of the records may contain any data in the field, and reading the value for the field would return nothing!

I hope this clarification is adequate.
KarstenK 30-Apr-15 6:47am    
What about converting the value to a string and returning it? Or can you use a stored procedure which does the work?
pani68 30-Apr-15 14:02pm    
I need to know the field properties without reading the value of the field.

1 solution

Don't use DAO.

According to this link, DAO does not support precision.

http://allenbrowne.com/ser-49.html#_ftn7[^]

Use ADO instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900