首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

asp 怎么用语句查询视图是否存在

2012-08-29 
asp 如何用语句查询视图是否存在?下面的函数是查询表是否存在,但视图是否存在怎么查?Function isTableExis

asp 如何用语句查询视图是否存在?
下面的函数是查询表是否存在,但视图是否存在怎么查?

Function isTableExists(DbConn, TableName ) '检查表是否存在
 Dim chkRs
 Set chkRs = DbConn.openSchema(20)
 chkRs.MoveFirst
 Do Until chkRs.EOF
  If chkRs("TABLE_TYPE") = "TABLE" then
  If chkRs("TABLE_NAME") = TableName Then
  isTableExists = True
  chkRs.Close
  Set chkRs = Nothing
  Exit Function
  End if
  End if
 chkRs.MoveNext
 Loop
 chkRs.Close
 Set chkRs = Nothing
 isTableExists = False
End Function


[解决办法]

VBScript code
<%sTable = "view_xxx"Response.Write isViewExists(sTable)Function isViewExists(sTable)    On Error Resume Next    Dim conn, sConn, oCat, colTables, oTable    sConn = "Provider=SQLOLEDB;Data source=127.0.0.1;Initial Catalog=db;User ID=sa;Password=xxx;"    Set conn = CreateObject("ADODB.Connection")    conn.Open sConn    Set oCat = CreateObject("ADOX.Catalog")    Set oCat.ActiveConnection = conn    Set colTables   = oCat.Tables    Set oTable      = colTables(sTable)    If oTable Is Nothing Then        isViewExists = False    Else        isViewExists = True    End If    Set oTable = Nothing    Set colTables = Nothing    Set oCat = Nothing    conn.Close    Set conn = NothingEnd Function%> 

热点排行