Advertisement
7_2009-2012 Data Structures #225086

Universal Database Updater

Why I wrote thise code: While working on a project, I realized that I was writing too many update statements. Not that it's hard, but hand coding update statements can feel like pulling teeth if you are working with large applications where you do a lot of updating. So why not create a dynamic update statement that saves time, and effort, and only needs to be written once? Okay, I admit it, I can be lazy sometimes. But this one is actually useful. This code takes values from a querystring and uses them to update two fields within a database record. It can be used for any table in any access database.

AI

Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Codice sorgente
original-source
<%
DataConnection = "Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\database\data.mdb;"
If request.querystring("state")="update" then
set Command1 = Server.CreateObject("ADODB.Command")
Command1.ActiveConnection = DataConnection
Command1.CommandText = "UPDATE "&request.querystring("table")&" SET "&request.querystring("field1")&"='"&request.querystring("field1_value")&"',"&request.querystring("field2")&"='"&request.querystring("field2_value")&"' WHERE "&request.querystring("where_value")&"="&request.querystring("primarykey")&""
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
if request.querystring("diagnostic") = "test" then 
Response.Write "the table <b>"&request.querystring("table")&" </b> has had the following values updated<BR>"
Response.Write "<B>"&request.querystring("field1")&" </b>has been updated to use <b>"&request.querystring("field1_value")&"</b> as it's value <BR>"
Response.Write "<B>"&request.querystring("field2")&" </b> has been updated to use <b>"&request.querystring("field2_value")&" </b>as it's value <BR>"
Response.Write "Your primary key is <B>"&request.querystring("where_value")&" </B> and it has updated where the value of that key is set to <b>"&request.querystring("primarykey")&"</b><p>"
Response.Write "This update is based on the values in the querystring. To change these values, or update a different set of fields or tables, then just change the values in the address bar above."
Response.Write "</p><p><b>Universal Querystring Updater</b><br>By <a href='http://sammoses.com'>Sam Moses</a> (c) 2002</p>"
end if
if request.querystring("diagnostic")="" then response.redirect "" &request.querystring("reset")&""
end if
%>
Commenti originali (3)
Recuperato da Wayback Machine