Announcement

Collapse
No announcement yet.

Insert an Array into db using JavaScript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Insert an Array into db using JavaScript

    Hi,

    I'm trying to use JavaScript to insert an array of integers into a db. Unfortunately, I'm not getting the syntax right and they're appearing as strings

    I can get the string patientID to INSERT correctly, but the resultVal integers appear as strings as well, throwing an error. How can I make resultVal[count] an integer?

    Code:
    for (count=0; count< $('resultVal').length; count++)
    {
    	query = CDRUpdate("INSERT IGNORE INTO resultValues (patientID, value) VALUES ('"+$('patientID')+"', '"+$('resultVal')[count]+"')");
    }
    Any ideas? I've also tried using a "for each" loop but couldn't get that to work either. If you know how to do either one, it'd be much appreciated.
    Last edited by DimitriA; 07-21-2011, 12:17 PM.

  • #2
    I'm not sure which database back end you're using, but I would put a CAST or CONVERT statement around the integer value in the INSERT statement. For example:
    Code:
    INSERT IGNORE INTO database.dbo.myTable (id, int_value) VALUES(2, CAST('001' AS INTEGER));
    Michael Arnold| Electronic Data Interchange Specialist

    PlayMaker CRM
    Sales Innovation for Home Care
    A Division of The ADAM Group
    115 Southeast Parkway Court | Franklin, TN 37064
    866.930.6847 | F: 866.232.6470 | PlayMakerCRM.com

    Comment


    • #3
      I got it. Thank you!

      Comment

      Working...
      X