資料|資料庫 很多人一定用過Query Analyzer,這個工具的功能如何如何,就不用我說了,這次給大家介紹下Web下的Query Analyzer,介面如圖1,使用ASP寫的。
(圖1)
來源程式如下:
<%
dim conn
dim connstr
on error resume next
if request("selectdb")="mdb" then
if request("dbname")<>"" then
connstr="DBQ="+server.mappath(request("dbname"))+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err.number<>0 then
err.clear
set conn=nothing
response.write "錯誤:資料庫連接出錯!"
else
if request("dbpass")<>"" then
conn.open connstr
else
Conn.Open connstr,"admin",request("dbpass")
end if
if err then
set conn=nothing
response.write "錯誤:資料庫連接出錯!!!<br>" + err.description
err.clear
end if
end if
end if
elseif request("selectdb")="mssql" then
if request("dbname")<>"" then
connstr = "Provider=SQLOLEDB.1"
connstr = connstr & ";Data Source=" & request("sqlip") 'sql_server資料庫
connstr = connstr & ";User ID=" & request("sqladmin") '資料庫伺服器使用者
connstr = connstr & ";Password=" & request("sqlpass") '登入口令
connstr = connstr & ";Initial Catalog=" & request("sqldb") '資料庫名
set conn=server.createobject("ADODB.CONNECTION")
if err.number<>0 then
err.clear
set conn=nothing
response.write "錯誤:資料庫連接出錯!"
else
conn.open connstr
if err then
set conn=nothing
response.write "錯誤:資料庫連接出錯!!!<br>" + err.description
err.clear
end if
end if
end if
end if
sub endConnection()
conn.close
set conn=nothing
end sub
%>
<HTML>
<HEAD>
<TITLE>Query Analyzer</TITLE>
<STYLE type=text/css>BODY {FONT-FAMILY: "宋體", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt}
P {FONT-FAMILY: "宋體", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt}
BR {FONT-FAMILY: "宋體", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt}
TD {FONT-FAMILY: "宋體", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt}
.p9 {FONT-SIZE: 9pt; LINE-HEIGHT: 14pt}
A:link {COLOR: #004080; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt; TEXT-DECORATION: none}
A:visited {COLOR: #004080; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt; TEXT-DECORATION: none}
A:hover {COLOR: #ff0000; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt; TEXT-DECORATION: underline}
.p105 {FONT-SIZE: 10.5pt}
INPUT.yellowbtn {BACKGROUND-COLOR: #88a3f2; COLOR: #000000; FONT-SIZE: 9pt}
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" topmargin="0">
<script language=JavaScript>
function setWB(x) {
document.main.whichbutton.value = x;
document.main.submit();
}
function showSQL(x) {
sqlvalue = document.main.sql.value;
if (x == 0) {
smsg = "\n怎樣使用sql語句協助:\n\n";
smsg = smsg + "1. 在選擇框裡選一個命令\n";
smsg = smsg + "2. 點擊[顯示]按鈕\n";
smsg = smsg + "3. sql語句會顯示在左邊的文字框裡面\n\n";
smsg = smsg + "4. 修改此語句來適合你資料庫結構\n\n";
smsg = smsg + "5. 根據語句查詢結果或執行命令\n\n";
alert(smsg); }
else if (x == 1) {
smsg = "SELECT columnName1, columnName2\n";
smsg = smsg + " FROM tableName\n";
smsg = smsg + " WHERE columnName = 'value'\n\n";
document.main.sql.value = smsg;
}
else if (x == 2) {
smsg = "INSERT INTO tableName\n";
smsg = smsg + " (columnName, IntegerColumnName)\n";
smsg = smsg + " VALUES ('value', numericValue)\n\n";
document.main.sql.value = smsg;
}
else if (x == 3) {
smsg = "UPDATE tableName\n";
smsg = smsg + " SET columnName = 'value'\n";
smsg = smsg + " WHERE columnName = 'value'\n\n";
document.main.sql.value = smsg;
}
else if (x == 4) {
smsg = "DELETE columnName\n";
smsg = smsg + " FROM tableName\n";
smsg = smsg + " WHERE columnName = 'value'\n\n";
document.main.sql.value = smsg;
}
else if (x == 5) {
smsg = "CREAT