Click here to Skip to main content
11,416,194 members (51,369 online)
Click here to Skip to main content
Articles » Database » Database » General » Downloads
Add your own
alternative version

Online DB Administration

, 17 Mar 2003
Online administration of your database. Create or modify tables, keys, and indexes. Edit or insert data.
<%@language=javascript%>
<!--#include file=common.asp-->
<!--#include file=b.grid.asp-->
<%
	function Content(Conn) {
		try {
			var sTable = Request.QueryString("table").Item;
			var sFilter = '';
			var rsKeys = null;

			try {
				if(GetFormValue("DisableLookup","")!="on") {
					rsKeys = Conn.OpenSchema(adSchemaForeignKeys);
					rsKeys.Filter = "FK_TABLE_NAME='"+sTable+"'";
					while(!rsKeys.EOF && false) {
						Out(rsKeys("FK_COLUMN_NAME").Value + " references " + 
							rsKeys("PK_TABLE_NAME").Value + "." + rsKeys("PK_COLUMN_NAME").Value +
							"<br>");
						rsKeys.MoveNext();
					}
				}
			}
			catch(e) {
				//DebugOut("FK error: " + e.description);
				rsKeys = null;
			}

			if(rsKeys) {
			}

			var rs = Server.CreateObject("ADODB.Recordset");
			try {
				rs.Open(sTable,Conn,adOpenStatic,adLockOptimistic,adCmdTable);
			}
			catch(e) {
				rs.Open("["+sTable+"]",Conn,adOpenStatic,adLockOptimistic,adCmdTable);
			}
			
			var Grid = new BGrid(rs);
			//Grid.SetOption("debug",true);
			Grid.SetOption("pagesize",20);
			if(rsKeys) {
				rsKeys.Filter = "FK_TABLE_NAME='"+sTable+"'";
				if(!rsKeys.EOF && !rsKeys.BOF) {
					Out('<table cellspacing="0" cellpadding="0"><tr>');
					while(!rsKeys.EOF) {
						var rsLookup = Server.CreateObject("ADODB.Recordset");
						var sName = rsKeys('PK_TABLE_NAME').Value;
						Out('<td><em>' + sName + '</em><br>');
						try {
							rsLookup.Open(sName,Conn,adOpenStatic,adLockOptimistic,adCmdTable);
						}
						catch(e) {
							rsLookup.Open('[' + sName + ']',Conn,adOpenStatic,adLockOptimistic,adCmdTable);
						}
					
						var dd = new BDropdown(sName,rsLookup,rsKeys('PK_COLUMN_NAME').Value);
						dd.Display();
						if(dd.GetValue()) {
							if(sFilter!='') sFilter += ' and ';
							sFilter += rsKeys('FK_COLUMN_NAME').Value + '=' + dd.GetValue();
							Grid.SetDefault(rsKeys('FK_COLUMN_NAME').Value,"select '" + dd.GetValue() + "'");
						}
						dd = null;
						rsLookup.Close();
						rsLookup = null;
						
						Out('</td><td>&nbsp;</td>');
						rsKeys.MoveNext();
					}
					Out('</tr></table><hr>');
				}
				
				for(var n=0;n<rs.Fields.Count;n++) {
					rsKeys.Filter = "FK_TABLE_NAME='"+sTable+"' AND FK_COLUMN_NAME='"+rs.Fields(n).Name+"'";
					if(!rsKeys.EOF && !rsKeys.BOF) {
						var rsLookup = Conn.Execute(rsKeys("PK_TABLE_NAME").Value);
						Grid.SetLookup(rs.Fields(n).Name,rsLookup,rsKeys("PK_COLUMN_NAME").Value);
					}
				}
				rsKeys.Close();
				rsKeys = null;
			}
			
			Grid.Process();
			rs.Requery();
			rs.Filter = sFilter;
			if(rs.RecordCount>0) rs.MoveFirst();
			Grid.Display();
			Grid = null;

			rs.Close();
			rs = null;

			Out("<input type=\"checkbox\" " + (GetFormValue("DisableLookup","")=="on"?"checked ":"") + "name=\"DisableLookup\" onclick=\"this.form.submit()\"/>Disable Lookups");
		}
		catch(e) {
			Out('\n<scr'+'ipt type="text/javascript">\nSetErrorMessage("'+e.description+'")\n</sc'+'ript>\n');
			throw e;
		}


		Out('<br>');
		Out('<table class="list" cellspacing="0" cellpadding="0">\n');
		Out('<tr>\n');
  		Out('<td>&nbsp;<a href=".">Back</a>&nbsp;</td>\n');
  		Out('</table>\n');
	}

	PageSetup();
	NewPageHeader();
	Content(Object.Conn);
	NewPageFooter();
	PageCleanup();
%>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Bjornar Henden
Web Developer
Norway Norway
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150427.4 | Last Updated 18 Mar 2003
Article Copyright 2002 by Bjornar Henden
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid