Click here to Skip to main content
15,895,746 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(Conn) {
		var nDataType = GetFormValue("typename","");

		// Ok, if user clicked "Add Field" we should be ready to go
		if(Request.Form("addfield").Count==1) {
			try {
				var sTableName = Request.QueryString("table").Item;
				var sql;
				if(IsJet(Conn))
					sql = "alter table [" + sTableName + "]";
				else
					sql = 'alter table "' + sTableName + '"';
				
				if(Request.Form("fieldname").Item!="") {
					if(IsJet(Conn))
						sql += ' add [' + Request.Form("fieldname").Item + ']';
					else
						sql += ' add "' + Request.Form("fieldname").Item + '"';
				}
				if(nDataType!="")
					sql += " " + nDataType;
				if(Request.Form("DefinedSize").Item!="") {
					sql += "(" + Request.Form("DefinedSize").Item + ")";
				} else if(Request.Form("NumericScale").Item!="" || Request.Form("Precision").Item!="") {
					sql += "(";
					if(Request.Form("Precision").Item!="")
						sql += Request.Form("Precision").Item;
					else
						sql += "0";
					sql += ",";
					if(Request.Form("NumericScale").Item!="")
						sql += Request.Form("NumericScale").Item;
					else
						sql += "0";
					sql += ")";
				}
				if(Request.Form("Nullable").Count==1)
					sql += " null";
				else
					sql += " not null";

				if(Request.Form("default").Item!="")
					sql += " default " + Request.Form("default").Item;

				if(Request.Form("Autoincrement").Count==1)
					sql += " identity";

				Conn.Execute(sql);
				EndPage("columns.asp?table="+Request.QueryString("table").Item);
			}
			catch(e) {
				Out('\n<s'+'cript type="text/javascript">\nSetErrorMessage("' + e.description + '");\n</scr'+'ipt>\n');
			}
		}

		Out('<table class="list" cellspacing="0" cellpadding="0" width="100%">');
		Out('<tr><th colspan="2">' + Request.QueryString("table").Item + '</th></tr>');
		Out("<tr><td nowrap=\"true\" width=\"1%\">Field Name:</td><td><input type=\"edit\" name=\"fieldname\" value=\""+GetFormValue("fieldname","")+"\"/></td></tr>");
		Out("<tr><td nowrap=\"true\">Data Type:</td><td>");

		Out("<select name=\"typename\">");
		if(nDataType=="") Out("<option/>");
		var rsProviderTypes = Conn.OpenSchema(adSchemaProviderTypes);
		while(!rsProviderTypes.EOF) {
			Out("<option ");
			if(nDataType==rsProviderTypes("TYPE_NAME").Value)
				Out("selected ");

			Out("value='"+rsProviderTypes("TYPE_NAME").Value+"'>" + rsProviderTypes("TYPE_NAME").Value + "</option>");
			rsProviderTypes.MoveNext();
		}
		Out("</select></td></tr>");
		rsProviderTypes.Close();
		rsProviderTypes = null;

		Out("<tr><td nowrap=\"true\">Defined Size:</td><td><input type=edit name=DefinedSize value=\""+GetFormValue("DefinedSize","")+"\"/></td></tr>");
		Out("<tr><td nowrap=\"true\">Precision:</td><td><input type=edit name=Precision value=\""+GetFormValue("Precision","")+"\"/></td></tr>");
		Out("<tr><td nowrap=\"true\">Numeric Scale:</td><td><input type=edit name=NumericScale value=\""+GetFormValue("NumericScale","")+"\"/></td></tr>");
		Out("<tr><td nowrap=\"true\">Nullable:</td><td><input type=checkbox " + (Request.Form("nullable").Count==1?"checked " : "") + "name=Nullable></td></tr>");
		Out("<tr><td nowrap=\"true\">Autoincrement:</td><td><input type=checkbox " + (Request.Form("Autoincrement").Count==1?"checked " : "") + "name=Autoincrement></td></tr>");
		Out("<tr><td nowrap=\"true\">Default:</td><td><input type=edit " + GetFormValue("default","") + " name=default></td></tr>");

		Out("<tr><td colspan=2><input type=\"submit\" name=\"addfield\" value=\"Create Column\"/></td></tr>");
		Out("</table>");

		oCat = null;

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