asp快速开发方法之数据操作实例代码第3/3页

 更新时间:2007年08月08日 11:05:52   作者:  

当然你也这以这样写:
<%
sql="insert into cnarticle(cn_title,cn_author,cn_content) values(' "&whattitle&" ',' "&whoauthor&" ',' "&whatcontent&" ')"
opendatabase
conn.execute(sql)
closedatabase
%>
考虑到可能删除语句我们会这么写:
sql="delect from cnarticle where id in(1,3,5,6,7,8)"

我新建一个类DeldataTable,直接使用DeldataTable.DeldataSql(tableName,DelField,id)完成记录的删除操作。
<%
Class DeldataTable
    dim tempvalue
    public Function DeldataSql(tableName,DelField,id)
        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
%>
以下是我的sql.asp文件,请自己进行增删
复制代码 <%
'用于查询数据
Class selectDataTable
    '查出记录
    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

相关文章

最新评论