1
Public 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
33
End Function
34
35
Public Function C(ByVal ObjRs)
36
ObjRs.close()
37
Set ObjRs = Nothing
38
End Function
39
40
Private 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
109
End Function
110
111
Private 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
120
End Function
121
End Class
122
%>
Public Function ReadTable(ByVal TableName,ByVal Condition,ByVal GetFieldNames)2
On Error Resume Next3
Dim rstGetValue,Sql,BaseCondition,arrTemp,arrStr,TempStr,i4
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 "&BaseCondition10
rstGetValue.Open Sql,idbConn,1,111
If rstGetValue.RecordCount > 0 Then12
If Instr(GetFieldNames,",")>0 Then13
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).Value17
Next18
TempStr = Split(arrStr,Chr(112)&Chr(112)&Chr(113))19
Else20
TempStr = rstGetValue.Fields(0).Value21
End If22
End If23
If Err.number <> 0 Then24
idbErr = idbErr & "获取数据出错!<br />"25
If debug Then idbErr = idbErr & "错误信息:"& Err.Description26
rstGetValue.close()27
Set rstGetValue = Nothing28
Exit Function29
End If30
rstGetValue.close()31
Set rstGetValue = Nothing32
ReadTable = TempStr33
End Function34

35
Public Function C(ByVal ObjRs)36
ObjRs.close()37
Set ObjRs = Nothing38
End Function39

40
Private Function ValueToSql(ByVal TableName, ByVal ValueList, ByVal sType)41
Dim StrTemp42
StrTemp = ValueList43
If IsArray(ValueList) Then44
StrTemp = ""45
Dim rsTemp, CurrentField, CurrentValue, i46
Set rsTemp = Server.CreateObject("adodb.recordset")47
With rsTemp48
.ActiveConnection = idbConn49
.CursorType = 150
.LockType = 151
.Source ="select * from [" & TableName & "] where 1 = -1"52
.Open53
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 Then57
Select Case sType58
Case 159
StrTemp = StrTemp & " And "60
Case Else61
StrTemp = StrTemp & ", "62
End Select63
End If64
If sType = 2 Then65
StrTemp = StrTemp & "[" & CurrentField & "]"66
Else67
Select Case .Fields(CurrentField).Type68
Case 7,133,134,135,8,129,200,201,202,20369
If sType = 3 Then70
StrTemp = StrTemp & "'"&CurrentValue&"'"71
Else72
StrTemp = StrTemp & "[" & CurrentField & "] = '"&CurrentValue&"'"73
End If74
Case 1175
If UCase(cstr(Trim(CurrentValue)))="TRUE" Then76
If sType = 3 Then77
StrTemp = StrTemp & "1"78
Else79
StrTemp = StrTemp & "[" & CurrentField & "] = 1"80
End If81
Else 82
If sType = 3 Then83
StrTemp = StrTemp & "0"84
Else85
StrTemp = StrTemp & "[" & CurrentField & "] = 0"86
End If87
End If88
Case Else89
If sType = 3 Then90
StrTemp = StrTemp & CurrentValue91
Else92
StrTemp = StrTemp & "[" & CurrentField & "] = " & CurrentValue93
End If94
End Select95
End If96
Next97
End With98
If Err.number <> 0 Then99
idbErr = idbErr & "生成SQL语句出错!<br />"100
If debug Then idbErr = idbErr & "错误信息:"& Err.Description101
rsTemp.close()102
Set rsTemp = Nothing103
Exit Function104
End If105
rsTemp.Close()106
Set rsTemp = Nothing107
End If108
ValueToSql = StrTemp109
End Function110

111
Private Function DoExecute(ByVal sql)112
Dim ExecuteCmd113
Set ExecuteCmd = Server.CreateObject("ADODB.Command")114
With ExecuteCmd115
.ActiveConnection = idbConn116
.CommandText = sql117
.Execute118
End With119
Set ExecuteCmd = Nothing120
End Function121
End Class122
%>
浙公网安备 33010602011771号