Inserting Data into Multiple Rows of Database
Inserting Data into Multiple Rows of Database
If you need to have a page that inserts mulitple rows based on the input submitted
from a form, your best bet is to write a bit of custom VBSript.
The MX Update Server Behavior works only for single row updates based on a unique row ID. You need a very similar statement that looks like this:
update table set column2 = 'new text' where column1 = 'value user entered'
Encoded with form values, it will look like this:
sSQL = "update dbo.TEST set DESCRIPTION = '" & Request("Description") & "' where name = '" & Request("Name") & "'"
If you examine the SQL statement that MX generates, you'll see that it uses the variables MM_EditColumn and MM_RecordID to hold the unique column name and the rowid of the record selected with the recordset you defined (required to create an update behavior). You may be tempted to doctor the MX code once you notice this, and modify the select statement in the chunk of code that does the update. Beware, though, that the next time you open the updage dialog and apply changes, your code will likely be vaperized.
The easiest and safest thing to do is copy the code that MX generates when you create an Update Behavior and modify it for your needs. Delete the "official" MX update bahavior when you're done scalping the code so things don't get confusing. This may sound strange, but it saves a good deal of time, and if you're a lazy coder like me, you'll appreciate the time savings.
I did just that will the following page. Note that it iterates on itself and just writes a message to the same page when it completes. You'll want to handle errors better than this, and probably redirect to another page when you're done.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> < !--#include file="Connections/MyConnectionsFile.asp" --> < % Dim sSQL Dim DBCmd If (CStr(Request("Submit")) <> "" And CStr(Request("Name")) <> "") Then sSQL = "update dbo.TEST set DESCRIPTION = '" & Request("Description") & "' where name = '" & Request("Name") & "'" ' execute the update <html> <body> </form> |
Comments
Can ASP Upload be added to this routine?
You must me logged in to write a comment.