中成网站建设
    成都做网站,就选中成网站建设!专业四川网站建设,成都网站建设服务提供商
            企业宣传网站建设、电子商务网站建设、OA办公系统。联系电话:028-66165255
    资讯列表  
 用Adodb.Stream的SaveToFile方…
 绝妙的asp生成静态页面html函数…
 关于页面缓存清除的方法小结_a…
 asp无限级分类加js收缩伸展功能…
 flash读取xml中文本格式的小问…
 区分 JavaScript、Jscript、VB…
 asp给access表增加列
 Asp时间相加问题使用DateAdd函…
 asp操作xml文档,自动生成换行…
 几款Access 在线管理工具(ASP…
 关于Html页面中大量连续英文字…
 ASP中正则表达式删除HTML代码,…
 ASP在access库里创建表,及判断…
 用javascript判断radio单选框是…
 WEB应用的缓存兼容性设计
    资讯详情  
ASP在access库里创建表,及判断表是否存在代码
发布时间:2009-09-16                  来源:成都网站建设--中成网建         【加入收藏】

ASP在access库里创建表,及判断表是否存在代码


Option Explicit

Const adSchemaTables = 20
Const ConnString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=data.mdb;"

Const TableNameToCreate = "TableDemo"
Const TableCreateSQL = "Create table TableDemo( id autoincrement(1,1) primary key, NumVal int, TxtVal Text );"
Const TableRemoveSQL = "drop table TableDemo;"

 

Dim TableCount
Dim Tables

Dim Conn
Set Conn = Server.CreateObject( "ADODB.Connection" )
Conn.Open ConnString
Response.Write "Table1 - " & isTableExists( Conn, "Table1" )
Response.Write "Table2 - " & isTableExists( Conn, "Table2" )
Response.Write "Table3 - " & isTableExists( Conn, "Table3" )
Response.Write ""

If Not isTableExists( Conn, TableNameToCreate ) Then
    Conn.Execute( TableCreateSQL )
    Response.Write ""
    Response.Write "Creating table " & TableNameToCreate & "... Done!"
    Response.Write ""
End if

Dim SQL, i
For i = 1 to 5
    SQL = "insert into TableDemo( NumVal, TxtVal ) values( "& 1000+i &", '"& "Rec100" & i &"' )"
    Conn.Execute( SQL )
    Response.Write SQL
Next

Response.Write ""

SQL = "select id, NumVal, TxtVal from TableDemo"
Dim Rs, N, Rows
Set Rs = Server.CreateObject( "ADODB.RecordSet" )
Rs.Open SQL, Conn, 1, 1
N = Rs.RecordCount
if N > 0 Then
    Rows = Rs.GetRows()
End if
Rs.Close
Set Rs = Nothing

Response.Write "Query table " & TableNameToCreate & " : " & N & " Record(s)."
Response.Write ""

Dim id
Dim NumVal
Dim TxtVal
If N > 0 Then
    Response.Write "================="
    Response.Write "id NumVal TxtVal"
    Response.Write "--------ā---------"
    For i = 0 to N-1
        id = Rows( 0, i )
        NumVal = Rows( 1, i )
        TxtVal = Rows( 2, i )
       
        Response.Write " " & id & "   " & NumVal & " " & TxtVal
    Next
    Response.Write "================="
End if

If isTableExists( Conn, TableNameToCreate ) Then
    Conn.Execute( TableRemoveSQL )
    Response.Write ""
    Response.Write "Removing table " & TableNameToCreate & "... Done!"
    Response.Write ""
End if


Conn.Close
Set Conn = Nothing

 

 

 

 


Function isTableExists( DbConn, TableName )
    Dim Rs
    Set Rs = DbConn.openSchema( adSchemaTables )
   
    Rs.MoveFirst
    Do Until Rs.EOF
        If Rs("TABLE_TYPE") = "TABLE" then
            If Rs("TABLE_NAME") = TableName Then
                isTableExists = True
                Rs.Close
                Set Rs = Nothing
                Exit Function
            End if
        End if
        Rs.MoveNext
    Loop
   
    Rs.Close
    Set Rs = Nothing
   
    isTableExists = False
End Function

 

 
上一篇:美国联邦巡回上诉法院周五推翻了关于微软赔偿阿尔卡特-朗讯
下一篇:最近10年及下个10年Apache最有影响的项目
【打印】    【关闭】    【字体变小】    【字体变大】

友情链接

首页  |  建站学院  |  网站建设  |  成功案例  |  业务体系  |  软件定制  |  解决方案  |  联系我们  |  免责声明
中成网建公司地址:四川省成都市双楠双安东巷1号18-3-5 电话:028-6616 5255 版权所有 @ 中成网建
成都网站建设网址:www.csccd.net www.csccd.cn 邮箱:web#csccd.net
信息产业部备案号:蜀ICP备08106559号