创建数据库、显示表及字段

发布时间:2007-03-26 20:08:00 阅读:888次

<%
Option Explicit
dim databasename '定义数据库名称
databasename="database.mdb" '数据库名称
dim databasepath '定义数据库存放路径
databasepath="E:Victor" '数据库绝对路径
dim databasever '定义数据库版本 2000 或者 97
databasever = "2000"

Function Createdfile(FilePath,FileName,Ver)
Dim Ca,dbver
select case ver
case "97"
dbver = "3.51"
case "2000"
dbver = "4.0"
end select
if dbver <> "" then
Set Ca = Server.CreateObject("ADOX.Catalog")
call Ca.Create("Provider=Microsoft.Jet.OLEDB." & dbver & ";Data Source=" & filepath & filename)
end if
End Function

Createdfile databasepath,databasename,databasever '创建数据库

%>

查看一个数据库的表及一个表中的字段:
<br/>

<!--#include file="conn.asp"-->
<%set rs=conn.openschema(20)
rs.movefirst
do while not rs.eof
if rs("TABLE_TYPE")="TABLE" then
response.write rs("TABLE_NAME")&"<br>"
end if
rs.movenext
loop%>

<br />
<%set rsa=server.CreateObject("adodb.recordset")
rsa.open "Select *from forum",conn,1,2
for i=0 to rsa.fields.count-1
response.write rsa.fields(i).name&"<br>"
next
%>
<br/>

判断数据库中的指定表是否存在:


<%
rem x=0 表示不存在,x=1 表示存在
%>
<!--#include file="conn.asp"-->
<%
set rsSchema=Conn.openSchema(20)
rsSchema.movefirst
x=0
Do Until rsSchema.EOF
if rsSchema("TABLE_TYPE")="TABLE" then
if rsSchema("TABLE_NAME")="forum" then
x=1
exit do
end if
end if
rsSchema.movenext
Loop
if x=0 then response.write"没有找到表forum!!!"
if x=1 then response.write"找到了forum"
%>

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:创建数据库、显示表及字段 出自老鄢博客 | 欢迎分享