Not yet rated

Problem

What is the simplest way to use the value from a mx:DateField in an update or insert query against SQLite? I have a simple form that the user fills out and I want to save the date to a DATE type field in SQLite. Secondarily, I have a value object that will use that same date. How do I assign the date value from the mx:DateField to a Date object? Thank you.

Solution

from http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/#comment-96981 Use Parameters

Detailed explanation

Did some looking around. This article explains in more detail than I needed

http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/#comment-96981

 

Answer to Primary Question:
- Use parameters in the SQL statement and set the value of the date parameter to the selectedDate of the mx:DateField
 
Answer to Secondary question:
- use selectedDate of the mx:DateField to assign to Value Object's date field eg myObj.DOB = edtDOB.selectedDate;
 
or use data binding.
 
...
 
stmt.text = "INSERT INTO PERSON "
+ "(FNAME, LNAME, DOB) "
+ "values(:FNAME, :LNAME, :DOB)";
 
stmt.parameters[":FNAME"] = edtFName.text;
stmt.parameters[":LNAME"] = edtLName.text;
stmt.parameters[":DOB"] = edtDOB.selectedDate;
 
stmt.execute();
 
 ...
 
<s:TextInput id="edtFName" />
<s:TextInput id="edtLName" />
<mx:DateField id="edtDOB" enabled="true" editable="true" />
 
...

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes