<%
On Error Resume Next
Set oCat = Server.CreateObject("ADOX.Catalog")
Set oTable = Server.CreateObject("ADOX.Table")
Set oColumn = Server.CreateObject("ADOX.Column")
Set oConn = Server.CreateObject("ADODB.Connection")
Dim sTableName, sMsg, sconn

sTableName = Request.QueryString("TableName")
sMsg = "<font color=green>OK</font>"

sConn = "Driver={Microsoft Access Driver (*.mdb)};DBQ=\\premfs5\sites\premium10\bvckvs\database\xxx.mdb;"
oConn.Open sConn
oCat.ActiveConnection = oConn


Select Case Request.QueryString("DBAction")
	Case "View"
		If sTableName="" Then
			sMsg = "You must select a table from the list."
			sView = sView & fnShowTables()
		Else
			sMSG = "View: " & sTableName
			sView = "<table><tr><td align=left valign=top>" & fnShowTables() & "</td><td align=left valign=top>" & fnShowTable() & "</td></tr></table>"
		End If
	Case "Drop"
		If sTableName="" Then
			sMsg = "You must select a table from the list."
			sView = sView & fnShowTables
		Else
			sSQL = "DROP TABLE " & sTableName & ";"
			oConn.Execute sSQL
			sMsg = "Dropped Table: " & sTableName
			sView = fnShowTables()
		End If
	Case "Create"
		sMsg = "Creating new table..."
			sView = "<table><tr><td align=left valign=top>" & fnShowTables() & "</td><td align=left valign=top>" & fnShowCreateTable() & "</td></tr></table>"
	Case "CommitCreate"
		sSQL = "CREATE TABLE " & sTableName & " (" & Request.QueryString("ColumnDefs") & ");"
		oConn.Execute sSQL
		sMsg = "Created table: " & sTableName
		sView = fnShowTables()
	Case Else
		sMsg = ""
		sView = fnShowTables()
End Select


Function fnShowTables()
  Dim sRetVal
	sRetVal = "<form method='get' id='frmCatalog' name='frmCatalog'><table border='0' cellpadding='0' cellspacing='0' >"
	sRetVal = sRetVal & "<tr><th align=left valign=top>Tables:</th></tr>"
	sRetVal = sRetVal & "<tr><td align=left valign=top><select id='TableName' name='TableName' size='8'>"
	For Each oTable in oCat.Tables
		sRetVal = sRetVal & "<option value='" & Server.HTMLEncode(oTable.Name) & "'>" & Server.HTMLEncode(oTable.Name) & "</option>"
	Next
	sRetVal = sRetVal & "</select></td></tr>"
	sRetVal = sRetVal & "<tr><td align=left valign=top>"
	sRetVal = sRetVal & "<input type='submit' id='DBAction' name='DBAction' value='View' />"
	sRetVal = sRetVal & "<input type='submit' id='DBAction' name='DBAction' value='Drop' />"
	sRetVal = sRetVal & "<input type='submit' id='DBAction' name='DBAction' value='Create' />"
	sRetVal = sRetVal & "</td></tr>"
	sRetVal = sRetVal & "</table></form>"
  fnShowTables = sRetVal
End Function

Function fnShowTable()
  Dim sRetVal
	Set oTable = oCat.Tables(sTableName)
	sRetVal = "<form method='get' id='frmTable' name='frmTable'><table>"
	sRetVal = sRetVal & "<tr><th align=left valign=top>Table Name:</th>"
	sRetVal = sRetVal & "<td align=left valign=top>" & oTable.Name
	sRetVal = sRetVal & "</td></tr>"
	sRetVal = sRetVal & "<tr><th align=left valign=top>Table Type:</th>"
	sRetVal = sRetVal & "<td align=left valign=top>" & oTable.Type
	sRetVal = sRetVal & "</td></tr>"
	sRetVal = sRetVal & "<tr><th align=left valign=top>Date Created:</th>"
	sRetVal = sRetVal & "<td align=left valign=top>" & oTable.DateCreated
	sRetVal = sRetVal & "</td></tr>"
	sRetVal = sRetVal & "<tr><th align=left valign=top>Date Modified:</th>"
	sRetVal = sRetVal & "<td align=left valign=top>" & oTable.DateModified
	sRetVal = sRetVal & "</td></tr>"
	sRetVal = sRetVal & "<tr bgcolor='aqua'><th colspan=2>Columns:</th></tr>"
	sRetVal = sRetVal & "<tr><th align=left valign=top >Name:</th><th align=left valign=top>Type:</th></tr>"
	For Each oColumn in oCat.Tables(sTableName).Columns
		sRetVal = sRetVal & "<tr><td align=left valign=top>" & oColumn.Name & "</td>"
		sRetVal = sRetVal & "<td align=left valign=top>" & oColumn.Type
		sRetVal = sRetVal & "</td></tr>"
	Next
  fnShowTable = sRetVal
End Function

Function fnShowCreateTable()
  Dim sRetVal
	sRetVal = "<form method='get' id='frmTable' name='frmTable'><table>"
	sRetVal = sRetVal & "<tr><th align=left valign=top>Table Name:</th>"
	sRetVal = sRetVal & "<td align=left valign=top><input type='TableName' name='TableName' value='" & sTableName & "' /></td></tr>"
	sRetVal = sRetVal & "<tr><th align=left valign=top>Column Definitions:</th>"
	sRetVal = sRetVal & "<td align=left valign=top><input type='ColumnDefs' name='ColumnDefs' value='' /></td></tr>"
	sRetVal = sRetVal & "<tr><td align=right valign=top colspan=2><input type='submit' id='DBAction' name='DBAction' value='CommitCreate' /></td></tr>"
  fnShowCreateTable = sRetVal
End Function


%>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html><head>
	<title>Database Fronte-End for ASP</title>
	<meta name="description" content="Database Front-End for ASP">
	<meta name="keywords" content="Kaufman, Sanders, Bucky, .NET, MCSD">
	<meta http-equiv="Refresh" content="3600">
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<meta http-equiv="Content-Language" content="en-us">
	<meta name="Author" content="Sanders Kaufman / www.kaufman.net">
	<meta name="ROBOTS" content="ALL">
	<meta name="distribution" content="global">
	<meta name="revisit-after" content="2 weeks">
	<meta name="copyright" content="MMII">
</head><body>

<script language='javascript' id='jsSubmit' name='jsSubmit'>
	function cmdSubmit(sDBAction, oForm) {
		oForm.dbAction.value=sDBAction;
		oForm.submit();
	}
</script>

<table border=1>
<tr>
	<th align=left valign=top><h1>DB-FE ASP</h1></th>
	<td align=left valign=top>Connection String: <% = sConn %></td>
</tr><tr>
	<th colspan=2 align='center' valign='top'><% = sMsg %></th>
</tr><tr>
	<td colspan=2 align='left' valign='top'><% = sView %></td>
</tr>
</table>

</body></html>
<% oConn.Close %>