WEB开发网
开发学院WEB开发ASP ASP快速开发方法之数据操作 阅读

ASP快速开发方法之数据操作

 2007-08-08 12:05:40 来源:WEB开发网   
核心提示: <%'用于查询数据Class DataTable'查出记录public Function SelectData(sql)If sql<>"" thenopendatabaseRs.open sql,conn,1,1If not Rs.e
<%
'用于查询数据
Class DataTable
  '查出记录
  public Function SelectData(sql)
    If sql<>"" then
      opendatabase
      Rs.open sql,conn,1,1
      If not Rs.eof then
        Thedata=Rs.GetRows(-1)
        Closedatabase
      Else
        Closedatabase
      End If
    End If
    SelectData=Thedata
  End Function
  '查出记录条数
  public Function SelectDataNum(sql)
    If sql<>"" then
      Opendatabase
      Rs.open sql,conn,1,1
      If not Rs.eof then
        Thedata=Rs.GetRows(-1)
        Closedatabase
        Num=ubound(Thedata,2)
      Else
        Closedatabase
      End If
    End If
    SelectDataNum=Num
  End Function
  '使用select count(*) from tablename 查出记录有数
  public Function SelectCountNum(sql)
    If sql<>"" then
      Opendatabase
      Rs.open sql,conn,1,1
      If not Rs.eof then
        Thedata=Rs.GetRows(-1)
        Closedatabase
        Num=Thedata(0,0)
      Else
        Closedatabase
      End If
    End If
    SelectCountNum=Num
  End Function
  '将查询的数据全部生成隐藏值
  public Function GetHiddenData(sql)
    dim tempvalue
    If sql<>"" then
      Opendatabase
      Rs.open sql,conn,1,1
      If not Rs.eof then
        Thedata=Rs.getRows(-1)
        TheFieldCount=rs.fields.count
        For i=0 to TheFieldCount-1
          TheFieldList = TheFieldList & Rs.fields(i).name & ","
        Next
        Closedatabase
        TheField = split(TheFieldList,",")
        For i=0 to TheFieldCount-1
          tempvalue = tempvalue & "<input type=""hidden"" id="""&TheField(i)&""" name="""&TheField(i)&""" value="""&Thedata(i,0)&""" />"
        Next
      Else
        Closedatabase
      End If
    End If
    GetHiddenData=tempvalue
  End Function
  public Function UpdataSql(sql)
    If sql<>"" then
      Opendatabase
      conn.execute(sql)
      Closedatabase
    End If
  End Function
  
  public Function DeldataSql(tableName,DelField,id)
    dim tempvalue
    If tableName<>"" and id<>"" then
      sql="delete from "&tableName
      If isnumeric(id) and instr(id,",")=0 then
        sql = sql & " where "&DelField&" = "&id
      Else
        sql = sql & " where "&DelField&" in ("& id &")"
      End If
      Opendatabase
        conn.execute(sql)
      Closedatabase
      tempvalue=true
    Else
      tempvalue=false
    End If
    DeldataSql=tempvalue
  End Function
End Class
%>

上一页  2 3 4 5 6 7 

Tags:ASP 快速 开发

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接