怎么动态提取数据库字段来查询?

根据数据库字段来进行查询,但需要做成动态的,比如:
库中有studentNo,studentName,score现在根据这三个放在一个下拉框里选择一个来做为查询条件来查,如果删掉了一个字段则根据剩下两个来查。
---------------------------------------------------------------

dim sql

sql = "select * from tablename where 1 = 1 "

rs.open "你的表"
for i = 0 to rs.fields.count -1
fieldNam = rs.fields(i).name
inputVal = getInputVal(fieldNam)
createSqlStr(fieldNam,inputVal)
next

sub createSqlStr(fieldNam,inputVal)
if inputVal <> "" then sql &= " and " & fieldNam & " ='" & inputVal & "' "
end sub

function getInputVal(fieldNam)
for each item in request.Form
if item = fieldNam then
getInputVal = Request.form(item)
exit function
end if
next
end function

Published At
Categories with Web编程
Tagged with
comments powered by Disqus