Skip navigation
chathaf
Currently Being Moderated

Problems inserting into Access table

Apr 19, 2006 2:36 PM


I've used MX's insert behaviours several times before (for simple db inserts), but I'm getting an error at the ' MM_editCmd.Execute(); line. (The page is mcneillmanagement.com/test.asp.) It's a very simple entry, and I can't see any problems with the code. Any suggestions?
 
Replies
  • Currently Being Moderated
    Apr 19, 2006 2:40 PM   in reply to chathaf
    Write the value of MM_editQuery to the page so you can see if it's constructed properly.
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 23, 2006 7:48 PM   in reply to chathaf
    The word 'date' is reserved in SQL and should never be used to name database
    fields.

    --
    Paul Whitham
    Certified Dreamweaver MX2004 Professional
    Adobe Community Expert - Dreamweaver

    Valleybiz Internet Design
    www.valleybiz.net

    "chathaf" <webforumsuser@macromedia.com> wrote in message
    news:e26age$r3m$1@forums.macromedia.com...
    >
    > I've used MX's insert behaviours several times before (for simple db
    > inserts),
    > but I'm getting an error at the ' MM_editCmd.Execute(); line. (The page
    > is
    > mcneillmanagement.com/test.asp.) It's a very simple entry, and I can't see
    > any
    > problems with the code. Any suggestions?
    >
    > <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
    > <!--#include file="../Connections/testing.asp" -->
    > <%
    > // *** Edit Operations: declare variables
    >
    > // set the form action variable
    > var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
    > if (Request.QueryString) {
    > MM_editAction += "?" + Request.QueryString;
    > }
    >
    > // boolean to abort record edit
    > var MM_abortEdit = false;
    >
    > // query string to execute
    > var MM_editQuery = "";
    > %>
    > <%
    > // *** Insert Record: set variables
    >
    > if (String(Request("MM_insert")) == "form1") {
    >
    > var MM_editConnection = MM_testing_STRING;
    > var MM_editTable = "educational_entry";
    > var MM_editRedirectUrl = "educational.asp";
    > var MM_fieldsStr = "date|value|comments|value";
    > var MM_columnsStr = "date|',none,''|body|',none,''";
    >
    > // create the MM_fields and MM_columns arrays
    > var MM_fields = MM_fieldsStr.split("|");
    > var MM_columns = MM_columnsStr.split("|");
    >
    > // set the form values
    > for (var i=0; i+1 < MM_fields.length; i+=2) {
    > MM_fields[i+1] = String(Request.Form(MM_fields ));
    > }
    >
    > // append the query string to the redirect URL
    > if (MM_editRedirectUrl && Request.QueryString &&
    > Request.QueryString.Count >
    > 0) {
    > MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?')
    > == -1)?"?":"&") +
    > Request.QueryString;
    > }
    > }
    > %>
    > <%
    > // *** Insert Record: construct a sql insert statement and execute it
    >
    > if (String(Request("MM_insert")) != "undefined") {
    >
    > // create the sql insert statement
    > var MM_tableValues = "", MM_dbValues = "";
    > for (var i=0; i+1 < MM_fields.length; i+=2) {
    > var formVal = MM_fields[i+1];
    > var MM_typesArray = MM_columns[i+1].split(",");
    > var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
    > var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
    > var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
    > if (formVal == "" || formVal == "undefined") {
    > formVal = emptyVal;
    > } else {
    > if (altVal != "") {
    > formVal = altVal;
    > } else if (delim == "'") { // escape quotes
    > formVal = "'" + formVal.replace(/'/g,"''") + "'";
    > } else {
    > formVal = delim + formVal + delim;
    > }
    > }
    > MM_tableValues += ((i != 0) ? "," : "") + MM_columns
    ;
    > MM_dbValues += ((i != 0) ? "," : "") + formVal;
    > }
    > MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues +
    > ")
    > values (" + MM_dbValues + ")";
    >
    > if (!MM_abortEdit) {
    > // execute the insert
    > var MM_editCmd = Server.CreateObject('ADODB.Command');
    > MM_editCmd.ActiveConnection = MM_editConnection;
    > MM_editCmd.CommandText = MM_editQuery;
    > MM_editCmd.Execute();
    > MM_editCmd.ActiveConnection.Close();
    >
    > if (MM_editRedirectUrl) {
    > Response.Redirect(MM_editRedirectUrl);
    > }
    > }
    >
    > }
    > %>
    > <%
    > var Recordset1 = Server.CreateObject("ADODB.Recordset");
    > Recordset1.ActiveConnection = MM_testing_STRING;
    > Recordset1.Source = "SELECT date, body FROM educational_entry";
    > Recordset1.CursorType = 0;
    > Recordset1.CursorLocation = 2;
    > Recordset1.LockType = 1;
    > Recordset1.Open();
    > var Recordset1_numRows = 0;
    > %>
    >


     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 9:08 AM   in reply to chathaf

    hay like want you type on your page

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)