- 积分
- 528
- 明经币
- 个
- 注册时间
- 2005-6-10
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2005-7-1 17:44:00
|
显示全部楼层
下面是我前几天做的一个Access的应用中的一部分,一个很标准的ADO数据存取程序,供你参考:
_____________________________________________________________
Private Sub Calc(bolMode As Boolean) Call Init Dim curTotalArea(20) As Long Dim curTotalFee(10) As Long
Set con = Application.CurrentProject.Connection Set rs = CreateObject("ADODB.Recordset") stSql = "SELECT * FROM [房屋结构类型]" rs.Open stSql, con, adOpenStatic i = 0 While Not rs.EOF curType(i) = rs![结构类型] curFee(i) = CInt(rs![补偿标准]) i = i + 1 rs.MoveNext Wend rs.Close stSql = "SELECT * FROM [年限折旧标准]" rs.Open stSql, con i = 0 While Not rs.EOF curYearBegin(i) = CInt(rs![竣工年限(开始)]) curYearEnd(i) = CInt(rs![竣工年限(结束)]) curRate(i) = CSng(rs![折旧比率]) i = i + 1 rs.MoveNext Wend rs.Close stSql = "SELECT * FROM [清违资料登记表] " stSql = stSql & "WHERE [地址] Not Like '%%环城%%' And [地址] Not Like '%%国道%%' And [地址] Not Like '%%红岩%%' And [地址] Not Like '%%床单%%' And [地址] Not Like '%%凯运%%' And [地址] Not Like '%%桐荫坪%%' And [地址] Not Like '%%东门北路%%'" stSql = stSql & "And [拆迁区内] = True ORDER BY [证号]" rs.Open stSql, con, adOpenKeyset, adLockOptimistic strMsg = "数据统计中..." varReturn = SysCmd(acSysCmdInitMeter, strMsg, rs.RecordCount) i = 0 j = 0 While Not rs.EOF i = i + 1 varReturn = SysCmd(acSysCmdUpdateMeter, i) If Not IsNull(rs![A建筑面积]) Then rs![A折价] = CSng(rs![A建筑面积]) * curFee(getFee(rs![A房屋结构])) * curRate(getRate(rs![A建筑竣工时间])) curTotalArea(getFee(rs![A房屋结构])) = curTotalArea(getFee(rs![A房屋结构])) + CSng(rs![A建筑面积]) * 100 curTotalFee(getFee(rs![A房屋结构])) = curTotalFee(getFee(rs![A房屋结构])) + CSng(rs![A折价]) Else rs![A折价] = 0 End If If Not IsNull(rs![B建筑面积]) Then rs![B折价] = CSng(rs![B建筑面积]) * curFee(getFee(rs![B房屋结构])) * curRate(getRate(rs![B建筑竣工时间])) curTotalArea(getFee(rs![B房屋结构])) = curTotalArea(getFee(rs![B房屋结构])) + CSng(rs![B建筑面积]) * 100 curTotalFee(getFee(rs![B房屋结构])) = curTotalFee(getFee(rs![B房屋结构])) + CSng(rs![B折价]) Else rs![B折价] = 0 End If If Not IsNull(rs![C建筑面积]) Then rs![C折价] = CSng(rs![C建筑面积]) * curFee(getFee(rs![C房屋结构])) * curRate(getRate(rs![C建筑竣工时间])) curTotalArea(getFee(rs![C房屋结构])) = curTotalArea(getFee(rs![C房屋结构])) + CSng(rs![C建筑面积]) * 100 curTotalFee(getFee(rs![C房屋结构])) = curTotalFee(getFee(rs![C房屋结构])) + CSng(rs![C折价]) Else rs![C折价] = 0 End If If Not IsNull(rs![D建筑面积]) Then rs![D折价] = CSng(rs![D建筑面积]) * curFee(getFee(rs![D房屋结构])) * curRate(getRate(rs![D建筑竣工时间])) curTotalArea(getFee(rs![D房屋结构])) = curTotalArea(getFee(rs![D房屋结构])) + CSng(rs![D建筑面积]) * 100 curTotalFee(getFee(rs![D房屋结构])) = curTotalFee(getFee(rs![D房屋结构])) + CSng(rs![D折价]) Else rs![D折价] = 0 End If If Not IsNull(rs![E建筑面积]) Then rs![E折价] = CSng(rs![E建筑面积]) * curFee(getFee(rs![E房屋结构])) * curRate(getRate(rs![E建筑竣工时间])) curTotalArea(getFee(rs![E房屋结构])) = curTotalArea(getFee(rs![E房屋结构])) + CSng(rs![E建筑面积]) * 100 curTotalFee(getFee(rs![E房屋结构])) = curTotalFee(getFee(rs![E房屋结构])) + CSng(rs![E折价]) Else rs![E折价] = 0 End If If Not IsNull(rs![F建筑面积]) Then rs![F折价] = CSng(rs![F建筑面积]) * curFee(getFee(rs![F房屋结构])) * curRate(getRate(rs![F建筑竣工时间])) curTotalArea(getFee(rs![F房屋结构])) = curTotalArea(getFee(rs![F房屋结构])) + CSng(rs![F建筑面积]) * 100 curTotalFee(getFee(rs![F房屋结构])) = curTotalFee(getFee(rs![F房屋结构])) + CSng(rs![F折价]) Else rs![F折价] = 0 End If rs![Z折价总计] = rs![A折价] + rs![B折价] + rs![C折价] + rs![D折价] + rs![E折价] + rs![F折价] rs.Update rs.MoveNext Wend Debug.Print "总记录条数:" & i rs.Close stSql = "SELECT * FROM [房屋结构类型] " rs.Open stSql, con, adOpenForwardOnly, adLockOptimistic While Not rs.EOF rs![总面积] = curTotalArea(getFee(rs![结构类型])) / 100 rs![总补偿费] = curTotalFee(getFee(rs![结构类型])) rs.Update rs.MoveNext Wend rs.Close
varReturn = SysCmd(acSysCmdClearStatus) End Sub
|
|