专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Access

VC++ ADO Access,怎么能够得到字段中设定的小数位数

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
VC++ ADO Access,如何能够得到字段中设定的小数位数?
比如一个双精度的字段,设定小数位数最大为8位,如何从结果集中取得这个设定值?
我的SQL查询的方法如下:

C/C++ code

_ConnectionPtr pConn;
_RecordsetPtr pRec;
pConn.CreateInstance(__uuidof(Connection));
pConn->Open(_bstr_t(strDataSource), "", "", adConnectUnspecified);
pRec = pConn->Execute(_bstr_t(strQuery), 0, adCmdText);



------解决方案--------------------
DAO 中使用 filed 对象的Property集合属性,然后设置或添加其中的format属性。

下面是手册中的例子。
VB code
CreateProperty Method Example

This example tries to set the value of a user-defined property. If the property doesn't exist, it uses the CreateProperty method to create and set the value of the new property. The SetProperty procedure is required for this procedure to run.

Sub CreatePropertyX()

   Dim dbsNorthwind As Database
   Dim prpLoop As Property

   Set dbsNorthwind = OpenDatabase("Northwind.mdb")

   ' Set the Archive property to True.
   SetProperty dbsNorthwind, "Archive", True
   
   With dbsNorthwind
      Debug.Print "Properties of " & .Name
      
      ' Enumerate Properties collection of the Northwind 
      ' database.
      For Each prpLoop In .Properties
         If prpLoop <> "" Then Debug.Print "  " & _
            prpLoop.Name & " = " & prpLoop
      Next prpLoop

      ' Delete the new property since this is a 
      ' demonstration.
      .Properties.Delete "Archive"

      .Close
   End With

End Sub

Sub SetProperty(dbsTemp As Database, strName As String, _
   booTemp As Boolean)

   Dim prpNew As Property
   Dim errLoop As Error

   ' Attempt to set the specified property.
   On Error GoTo Err_Property
   dbsTemp.Properties("strName") = booTemp
   On Error GoTo 0

   Exit Sub

Err_Property:

   ' Error 3270 means that the property was not found.
   If DBEngine.Errors(0).Number = 3270 Then
      ' Create property, set its value, and append it to the 
      ' Properties collection.
      Set prpNew = dbsTemp.CreateProperty(strName, _
         dbBoolean, booTemp)
      dbsTemp.Properties.Append prpNew
      Resume Next
   Else
      ' If different error has occurred, display message.
      For Each errLoop In DBEngine.Errors
         MsgBox "Error number: " & errLoop.Number & vbCr & _
            errLoop.Description
      Next errLoop
      End
   End If

End Sub
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: