asp获取表结构,并返回特定结果
只写了很简单的数据类型,对于更多的数据类型,请更改代码
<%
Dim TblName : TblName = SafeSql(GetRequest("tbl","",1,0))%>
<form id="form1" name="form1" method="post" action="table.asp?action=show">
<input type="text" name="tbl" id="tbl" value="<%=TblName%>" />
<input type="submit" name="button" id="button" value="提交" />
</form>
<%
Dim Action : Action = GetRequest("action","GET",1,0)
If Action = "show" Then
Call Show()
End If
Sub Show()
Dim Rs,i,iCount : Set Rs = ExecuteSql("select top 1 * from " & TblName)
iCount = 0
For i = 0 To Rs.Fields.Count - 1
If iCount > 0 Then Response.Write ","
Response.write Rs(i).Name
iCount = iCount + 1
Next
Response.Write "<br />"
For i = 0 To Rs.Fields.Count - 1
Response.write i & " " & Rs(i).Name & "<br />"
Next
Response.Write "<br />insert into " & TblName & "("
iCount = 0
For i = 0 To Rs.Fields.Count - 1
If LCase(Rs(i).Name)<>"id" Then
If iCount > 0 Then Response.Write ","
Response.write Rs(i).Name
iCount = iCount + 1
End If
Next
Response.Write ") values("
iCount = 0
For i = 0 To Rs.Fields.Count - 1
If LCase(Rs(i).Name)<>"id" Then
If iCount > 0 Then Response.Write ","
If Rs(i).Type = 202 Then
Response.write "'""&" & Rs(i).Name & "&""'"
Else
Response.write """&" & Rs(i).Name & "&"""
End If
iCount = iCount + 1
End If
Next
Response.Write ") <br />update " & TblName & " set "
iCount = 0
For i = 0 To Rs.Fields.Count - 1
If LCase(Rs(i).Name)<>"id" Then
If iCount > 0 Then Response.Write ","
If Rs(i).Type = 202 Then
Response.write Rs(i).Name & "='""&" & Rs(i).Name & "&""'"
Else
Response.write Rs(i).Name & "=""&" &Rs(i).Name & "&"""
End If
iCount = iCount + 1
End If
Next
Response.Write "where ID=""&ID<br />"
For i = 0 To Rs.Fields.Count - 1
If LCase(Rs(i).Name)<>"id" Then
Response.write "Rs(""" & Rs(i).Name & """) = " & Rs(i).Name & "<br />"
End If
Next
Rs.Close : Set Rs = Nothing
End Sub
%>
------------------------------------------------------------------------------------------
结果
------------------------------------------------------------------------------------------
这个是将查询放进数组时,查询的字段
Id,Title,eName,Parent,Child,Url,Sort,UpImg,Content,Template,ArtTemp,PubDate,IsLock,ItemTemplate
对应的数组中某字段的索引号
0 Id
1 Title
2 eName
3 Parent
4 Child
5 Url
6 Sort
7 UpImg
8 Content
9 Template
10 ArtTemp
11 PubDate
12 IsLock
13 ItemTemplate
插入操作
insert into Mall_acata(Title,eName,Parent,Child,Url,Sort,UpImg,Content,Template,ArtTemp,PubDate,IsLock,ItemTemplate) values('"&Title&"','"&eName&"',"&Parent&","&Child&",'"&Url&"',"&Sort&",'"&UpImg&"',"&Content&","&Template&","&ArtTemp&","&PubDate&","&IsLock&","&ItemTemplate&")
更新操作
update Mall_acata set Title='"&Title&"',eName='"&eName&"',Parent="&Parent&",Child="&Child&",Url='"&Url&"',Sort="&Sort&",UpImg='"&UpImg&"',Content="&Content&",Template="&Template&",ArtTemp="&ArtTemp&",PubDate="&PubDate&",IsLock="&IsLock&",ItemTemplate="&ItemTemplate&"where ID="&ID
更新操作
Rs("Title") = Title
Rs("eName") = eName
Rs("Parent") = Parent
Rs("Child") = Child
Rs("Url") = Url
Rs("Sort") = Sort
Rs("UpImg") = UpImg
Rs("Content") = Content
Rs("Template") = Template
Rs("ArtTemp") = ArtTemp
Rs("PubDate") = PubDate
Rs("IsLock") = IsLock
Rs("ItemTemplate") = ItemTemplate