如何取得Access中数字字段的字段长度和精度?(100分)

  • 主题发起人 主题发起人 alaclp
  • 开始时间 开始时间
A

alaclp

Unregistered / Unconfirmed
GUEST, unregistred user!
如何取得Access中数字字段的字段长度和精度?
如:
字段a设置为单精度浮点数,精度为3,如何
编程取得其长度和精度?
 
这个问题不知道在Delphi中能否实现?
 
好像是这个 - Fields.DataType
试试
 
需要dao 的一些东西,查查以前的帖子
 
var tb:TTable;
....
tb := TTable.Create(self);
tb.DatabaseName := Tablename;
tb.TableName := TableName;
tb.open;
for i := 0 to tb.FieldCount - 1 do
begin
tb.Fields.DataSize
tb.Fields.DisplayWidth
end;
 
这个问题不能在Delphi中能否实现。你可以看TFields的属性,然后你再作一个实验:
用DELPHI作一个有字符和浮点的数据库程序,用DBEDIT连接,你可能发现,字符类型的,
DELPHI控制的很好,但浮点类型的,你能输入范围外的数,但保存时会报错。

这就说明了,DELPHI并不知道你的浮点类型数据总长是多少(这个也许知道:DataSize),
精度是多少。
 

ACCESS数据库中的浮点数好像是18位小数。
至于在ACCESS中设置的几位小数,我感觉不起作用,只是为ACCESS显示时使
用,实际存放依然是18位小数!

如果要显示指定位数的不如直接设置字段的DisplayFormat属性
例如:"#.000;-#.000;0"
 
我想通过编程方法取得上述数据,而不是通过数据测试或人工查看取得,
如何做到?
 
可以的,你使用ADOX完全没问题,看看MS的ADOX的帮助先,
 
比如,为单精度
tb.Fields.DataSize-----------8
tb.Fields.DisplayWidth---------10
好像是无法 获得小数位数,只是在显示时有用

 
>>我想通过编程方法取得上述数据,而不是通过数据测试或人工查看取得,如何做到?
这是DELPHI的帮助,你看看吧。也许你通过ADOX能得到,但ADO你不会得到的!!!

TField.Size-->Indicates the size used in the definition of the
physical database field for data types that support different sizes.
property Size: Integer; Description
The interpretation of Size depends on the data type.
The meaning of Size for different data types is given in the following table:
DataType Meaning of Size

ftBoolean Size is not used; its value is always 0.
ftSmallInt Size is not used; its value is always 0.
ftWord Size is not used; its value is always 0.
ftAutoInc Size is not used; its value is always 0.
ftDate Size is not used; its value is always 0.
ftInteger Size is not used; its value is always 0.
ftTime Size is not used; its value is always 0.
ftCurrency Size is not used; its value is always 0.
ftDateTime Size is not used; its value is always 0.
ftFloat Size is not used; its value is always 0.

ftBCD Size is the number of digits after the decimal place.
ftString Size is the maximum number of characters in the string.
ftVarBytes Size is the maximum number of bytes of data, not counting the first two bytes which indicate the actual number of bytes of data that were used.
ftBytes Size is the maximum number of bytes of data.
ftBlob Size is the number of bytes from the BLOB that are stored in the record buffer.
ftDBaseOle Size is the number of bytes from the DBase OLE BLOB that are stored in the record buffer.

ftFmtMemo Size is the number of bytes from the memo that are stored in the record buffer.
ftGraphic Size is the number of bytes from the image that are stored in the record buffer.
ftMemo Size is the number of characters from the memo that are stored in the record buffer.
ftParadoxOle Size is the number of bytes from the Paradox OLE BLOB that are stored in the record buffer.
ftTypedBinary Size is the number of bytes from the BLOB that are stored in the record buffer.

ftUnknown Size is not used; its value is always 0.
ftCursor Size is not used; its value is always 0.
ftADT Size is the total number of fields contained in the ADT field, including the fields of any fields that are of type ADT.
ftArray
ftReference Size is not used; its value is always 0.
ftDataSet Size is not used; its value is always 0.
 
AdoX好像是在Access中定义和操作数据的类
 
使用Adox库,以下代码:
procedure TForm1.Button1Click(Sender: TObject);
var
I, K : Integer;
C : _Catalog;
Name, Val: string;
begin
C := Cocatalog.Create;
C.Set_ActiveConnection(Ado.ConnectionObject);
K := C.Tables['b'].Columns['Id'].Properties.Count;
For I := 0 to K-1 do
begin
Name := C.Tables['b'].Columns['test'].Properties.Item.Name;
Val := String(C.Tables['b'].Columns['test'].Properties[Name].Value);
Memo1.Lines.Add(Name + ':' + Val);
end;
C := NIL;
end;
结果如下,但是并没有DecimalPlaces这个属性(此属性存储了小数位数的值):
Autoincrement:0
Default:0
Description:
Nullable:0
Fixed Length:-1
Seed:1
Increment:1
Jet OLEDB:Column Validation Text:
Jet OLEDB:Column Validation Rule:
Jet OLEDB:IISAM Not Last Column:0
Jet OLEDB:AutoGenerate:0
Jet OLEDB:One BLOB per Page:0
Jet OLEDB:Compressed UNICODE Strings:0
Jet OLEDB:Allow Zero Length:0
Jet OLEDB:Hyperlink:0
 
这个问题应该结束了吧?!
 
没有正确答案吗?
 
>>没有正确答案吗?
有呀,就是你不可能通过ADO得到。
 
那么,正确答案是什么呢?
ADOX我也试过了!
如果有正确答案,我想应该是用DAO3.6对象了;但是我导入了该对象库,
确不知道如何去使用它;
还请示以正确答案,否则,难以入眠啊?
 
对你的精神真是佩服,祝你找到解决方法!!!
 
DataSet.Fields.DataSize
DataSet.Fields.DisplayWidth

可以吗?
 
DataSet.Fields.DataSize
DataSet.Fields.DisplayWidth

可以吗?

这不是他要的精度。。。
 
后退
顶部