1Public Function ReadTable(ByVal TableName,ByVal Condition,ByVal GetFieldNames)
  2   On Error Resume Next
  3   Dim rstGetValue,Sql,BaseCondition,arrTemp,arrStr,TempStr,i
  4   TempStr = "" : arrStr = ""
  5   '给出SQL条件语句
  6   BaseCondition = ValueToSql(TableName,Condition,1)
  7'读取数据
  8   Set rstGetValue = Server.CreateObject("ADODB.Recordset")
  9   Sql = "Select "&GetFieldNames&" From ["&TableName&"] Where "&BaseCondition
 10   rstGetValue.Open Sql,idbConn,1,1
 11   If rstGetValue.RecordCount > 0 Then
 12      If Instr(GetFieldNames,",")>0 Then
 13         arrTemp = Split(GetFieldNames,",")
 14         For i = 0 To Ubound(arrTemp)
 15            If i<>0 Then arrStr = arrStr &Chr(112)&Chr(112)&Chr(113)
 16            arrStr = arrStr & rstGetValue.Fields(i).Value
 17         Next
 18         TempStr = Split(arrStr,Chr(112)&Chr(112)&Chr(113))
 19      Else
 20         TempStr = rstGetValue.Fields(0).Value
 21      End If
 22   End If
 23   If Err.number <> 0 Then
 24      idbErr = idbErr & "获取数据出错!<br />"
 25      If debug Then idbErr = idbErr & "错误信息:"& Err.Description
 26      rstGetValue.close()
 27      Set rstGetValue = Nothing
 28      Exit Function
 29   End If
 30   rstGetValue.close()
 31   Set rstGetValue = Nothing
 32   ReadTable = TempStr
 33End Function
 34
 35Public Function C(ByVal ObjRs)
 36   ObjRs.close()
 37   Set ObjRs = Nothing
 38End Function
 39
 40Private Function ValueToSql(ByVal TableName, ByVal ValueList, ByVal sType)
 41   Dim StrTemp
 42   StrTemp = ValueList
 43   If IsArray(ValueList) Then
 44      StrTemp = ""
 45      Dim rsTemp, CurrentField, CurrentValue, i
 46      Set rsTemp = Server.CreateObject("adodb.recordset")
 47      With rsTemp
 48         .ActiveConnection = idbConn
 49         .CursorType = 1
 50         .LockType = 1
 51         .Source ="select * from [" & TableName & "] where 1 = -1"
 52         .Open
 53         For i = 0 to Ubound(ValueList)
 54            CurrentField = Left(ValueList(i),Instr(ValueList(i),":")-1)
 55            CurrentValue = Mid(ValueList(i),Instr(ValueList(i),":")+1)
 56            If i <> 0 Then
 57               Select Case sType
 58                  Case 1
 59                     StrTemp = StrTemp & " And "
 60                  Case Else
 61                     StrTemp = StrTemp & ""
 62               End Select
 63            End If
 64            If sType = 2 Then
 65               StrTemp = StrTemp & "[" & CurrentField & "]"
 66            Else
 67               Select Case .Fields(CurrentField).Type
 68                  Case 7,133,134,135,8,129,200,201,202,203
 69                     If sType = 3 Then
 70                        StrTemp = StrTemp & "'"&CurrentValue&"'"
 71                     Else
 72                        StrTemp = StrTemp & "[" & CurrentField & "] = '"&CurrentValue&"'"
 73                     End If
 74                  Case 11
 75                     If UCase(cstr(Trim(CurrentValue)))="TRUE" Then
 76                        If sType = 3 Then
 77                           StrTemp = StrTemp & "1"
 78                        Else
 79                           StrTemp = StrTemp & "[" & CurrentField & "] = 1"
 80                        End If
 81                     Else 
 82                        If sType = 3 Then
 83                           StrTemp = StrTemp & "0"
 84                        Else
 85                           StrTemp = StrTemp & "[" & CurrentField & "] = 0"
 86                        End If
 87                     End If
 88                  Case Else
 89                     If sType = 3 Then
 90                        StrTemp = StrTemp & CurrentValue
 91                     Else
 92                        StrTemp = StrTemp & "[" & CurrentField & "] = " & CurrentValue
 93                     End If
 94               End Select
 95            End If
 96         Next
 97      End With
 98      If Err.number <> 0 Then
 99         idbErr = idbErr & "生成SQL语句出错!<br />"
100         If debug Then idbErr = idbErr & "错误信息:"& Err.Description
101         rsTemp.close()
102         Set rsTemp = Nothing
103         Exit Function
104      End If
105      rsTemp.Close()
106      Set rsTemp = Nothing
107   End If
108   ValueToSql = StrTemp
109End Function
110
111Private Function DoExecute(ByVal sql)
112   Dim ExecuteCmd
113   Set ExecuteCmd = Server.CreateObject("ADODB.Command")
114   With ExecuteCmd
115      .ActiveConnection = idbConn
116      .CommandText = sql
117      .Execute
118   End With
119   Set ExecuteCmd = Nothing
120End Function
121End Class
122%>
posted on 2008-09-03 02:21  睿达团队  阅读(249)  评论(0编辑  收藏  举报