Click here to Skip to main content
15,895,709 members
Articles / Programming Languages / ASP

Online DB Administration

Rate me:
Please Sign up or sign in to vote.
3.88/5 (16 votes)
17 Mar 2003 237.3K   2.5K   58  
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(oConn) {
		var sViewName, sSQL;
		
		if(Request.Form("vname").Count==1) {
			sViewName = Request.Form("vname").Item;
		} else {
			sViewName = Request.QueryString("view").Item;
		}
		if(Request.Form("sql").Count==1) {
			sSQL = Request.Form("sql").Item;
		} else {
			var rs = oConn.OpenSchema(adSchemaViews);
			while(!rs.EOF) {
				if(rs('TABLE_NAME').Value==sViewName) {
					sSQL = rs('VIEW_DEFINITION').Value;
					break;
				}
				rs.MoveNext();
			}
			rs.Close();
			rs = null;
		}
	
		if(Request.Form("create").Count==1) {
			try {
				if(IsJet(oConn)) {
					oConn.Execute('drop view [' + sViewName + ']');
					oConn.Execute('create view [' + sViewName + '] as ' + sSQL);
				} else {
					oConn.Execute('drop view "' + sViewName + '"');
					oConn.Execute('create view "' + sViewName + '" as ' + sSQL);
				}
				EndPage('list_views.asp');
				return;
			}
			catch(e) {
				Out('\n<s'+'cript type="text/javascript">\nSetErrorMessage("' + e.description + '");\n</scr'+'ipt>\n');
			}
		}

		Out('<table class="list" style="width:100%" cellspacing="0" cellpadding="0">');
		Out('<tr><th>Enter name:</th></tr>');
		Out('<tr><td><input type="text" name="vname" value="'+sViewName+'"/></td></tr>');
		Out('<tr><th>Enter select statement:</th></tr>');
		Out('<tr><td><textarea name="sql">');
		Out(sSQL);
		Out('</textarea></td></tr>');

		Out('<tr><td><input type="submit" value="Test" name="test">\n');
		Out('<input type="submit" value="Create" name="create"></td></tr>\n');
		Out('</table>');
		
		if(Request.Form("test").Count==1) {
			try {
				var rs = Server.CreateObject("ADODB.Recordset");
			
				rs.Open(Request.Form("sql").Item,Object.Conn,adOpenStatic,adLockOptimistic,adCmdText);
				var Grid = new BGrid(rs);
				Grid.SetOption("pagesize",20);
				Grid.Process();
				rs.Requery();
				Out('<hr>');
				Grid.Display();
				Grid = null;

				rs.Close();
				rs = null;
			}
			catch(e) {
				Out('\n<s'+'cript type="text/javascript">\nSetErrorMessage("' + e.description + '");\n</scr'+'ipt>\n');
			}
		}

		Out('<br>');
		Out('<table class="list" cellspacing="0" cellpadding="0">\n');
		Out('<tr>\n');
  		Out('<td>&nbsp;<a href="list_views.asp">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


Written By
Web Developer
Norway Norway
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions