Is there a problem with my SQL statement? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Is there a problem with my SQL statement?

Last post 06-21-2006 06:41 AM by .mond. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 06-20-2006 07:08 AM

    • .mond
    • Not Ranked
    • Joined on 06-06-2006
    • Posts 16

    Is there a problem with my SQL statement?

    Hi,
    I am trying to customize my submit operation with JScript code so that only records that have a check mark in the 'submit' field will be sent to the database. Here is what i have come up with:
    quote:

    function submit_button::OnClick(eventObj)
    {
    // invoke the OnSubmitRequest event handler
    XDocument.Submit();
    }

    function XDocument::OnSubmitRequest(eventObj)
    {
    // If the submit operation is successful, set
    // eventObj.ReturnStatus = true;

    var objDOMNode; // stores a node in the DOM
    var objNamedNodeMap; // stores a collection of node attributes
    var objADOAdapter; // data adapter used to connect to the database
    var objDOMNodeList; // stores a list of DOM nodes
    var strSQLInsert; // stores an SQL insert statement


    // create a DOM Node List to put all the author nodes into
    try
    {
    objDOMNodeList = XDocument.DOM.selectNodes("/dfs:myFields/dfs:dataFields//d:authors2");
    }
    catch(ex)
    {
    XDocument.UI.Alert("Could not create XMLDOMNodeList object.\r\n"
    + ex.number + " - " + ex.description);
    // Return with eventObj.ReturnStatus == false (the default value)
    return;
    }

    // get the ADO data adapter for the database connection
    objADOAdapter = XDocument.QueryAdapter;

    // loop through all the records to find the ones that have the resubmit field checked
    while( objDOMNode = objDOMNodeList.nextNode() )
    {
    // get the attribute list for the current DOM Node
    objNamedNodeMap = objDOMNode.attributes;

    // <DEBUGGING>
    //XDocument.UI.Alert("objNamedNodeMap.getNamedItem(\"submit\"): " + objNamedNodeMap.getNamedItem("submit").xml);
    // </DEBUGGING>

    // Filter out the records that are to be submitted to the database
    if( objNamedNodeMap.getNamedItem("submit").nodeValue == "True" )
    {
    // store the attributes of the current node
    ln = objNamedNodeMap.getNamedItem("lname").nodeValue;
    fn = objNamedNodeMap.getNamedItem("fname").nodeValue;
    addr = objNamedNodeMap.getNamedItem("address").nodeValue;
    // if the string value is False assign 0 to avoid conversion problems when submitting to the database
    contract = ( (objNamedNodeMap.getNamedItem("contract").nodeValue == "False")? 0 : 1 );
    // always set to 0 so that when queries are run none of the records will have a check mark in the submit field
    // which could lead to new records being submitted by mistake
    submit = 0;

    // <DEBUGGING>
    XDocument.UI.Alert("contract: " + contract);
    // </DEBUGGING>

    strSQLInsert = "INSERT INTO authors2(lname,fname,address,contract,submit) VALUES(" +
    "'"+ln+"'" + "," + "'"+fn+"'" + "," + "'"+addr+"'" + "," + contract + "," + submit + ")";

    objADOAdapter.Command = strSQLInsert;

    // <DEBUGGING>
    XDocument.UI.Alert("SQL command: " + objADOAdapter.Command);
    // </DEBUGGING>

    try
    {
    objADOAdapter.Query();
    }
    catch(ex)
    {
    XDocument.UI.Alert("Error executing insert query.\r\n"
    + ex.number + " - " + ex.description);
    // Return with eventObj.ReturnStatus == false (the default value)
    return;
    }
    }
    // set eventObj.ReturnStatus = true
    eventObj.ReturnStatus = true;
    }
    // store the id attribute from the first author node encountered
    }



    With the above code i don't get any errors but when i check the corresponding database i see that a new record has not been added.

    Any idea what the problem might be?
  • 06-20-2006 07:38 AM In reply to

    Re: Is there a problem with my SQL statement?

    do you have insert permissions on the DB?
    Dean
    Charlotte, NC
  • 06-20-2006 07:54 AM In reply to

    • .mond
    • Not Ranked
    • Joined on 06-06-2006
    • Posts 16

    Re: Is there a problem with my SQL statement?

    yeah i think i have insert permissions, but wouldnt i get some sort of error message if i didnt?
  • 06-21-2006 06:41 AM In reply to

    • .mond
    • Not Ranked
    • Joined on 06-06-2006
    • Posts 16

    Re: Is there a problem with my SQL statement?

    Ok, i do have insert permissions and the query seems to be working but for some very strange reason it seems that the records are being added then being deleted.

    quote:

    1000 White Johnson Belleville 1 0
    1001 Green Marjorie Hillaby 1 0
    1002 Carson Cheryl Gibbons 1 0
    1003 O'Leary Michael Lowlands 1 0
    1004 Straight Dean West Terrace 1 0
    1005 Smith Meander Kensignton 0 0
    1006 Bennet Abraham Church Gap 1 0
    1007 Dull Ann Brittons Hill 1 0
    1008 Gringlesby Burt Pickwick Gap 1 0
    1009 Locksley Charlene Kirtons 1 0
    1010 Greene Morningstar Drill Hall 0 0
    1011 Blotchet-Halls Reginald Bonnets 1 0
    1012 Yokomoto Akiko Farmers 1 0
    1013 del Castillo Innes Turners Hall 1 0
    1014 DeFrance Michel Kendal 1 0
    1015 Stringer Dirk Vaucluse 0 0
    1021 Smith Meander Jackmans 1 1
    1025 Smith Meander Belleville 0 0
    1027 Jones Bob Here 0 0



    Notice the last four records, where there are gaps in the IDs of the records which would indicate that records were in fact added but for some odd reason deleted or discarded.
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.