Posted by mravel in SWF Studio V3 on Dec 04 2008, 11:53 am

Hi,

I'm a newbie with ADO and have been trying out for quite a few days to figure it out. The examples on the site seem to complex for a newbie and couldn't figure things out after searching the forums either. I've figured out how to use INSERT, UPDATE & DELETE but cant figure how to use setSQL to retrieve and populate onscreen textfields from a database.

I have a input text field named "fullname" and a button on the first frame

Here my code.

On frame 1.
ssCore.init();

// ============================================================
// Setup our connection and return data format.
// ============================================================
ssCore.ADO.setConnectString({connectString: "Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=False; Data Source=" + ssGlobals.ssStartDir + "\\example2.mdb;"});
ssCore.ADO.setTable({name: "DocName"});

ssCore.ADO.setRowFormat({format: "DLM"});
ssCore.ADO.setDelimiter({delimiter: "\t"});
ssCore.ADO.setSeparator({separator: "\n"});

ssCore.ADO.setSQL({sql:"SELECT * FROM DocName"});
// Open the database/table defined above.
ssCore.ADO.open();



CODE on the Button

on (press) {

_level0.fullname.text = _level0.currentRecord.FName;
ssCore.ADO.moveNext();

}


Keep getting undefined in the textfield on pressing the button. Pl help.


Posted by northcode in SWF Studio V3 on Dec 04 2008, 01:43 pm

SWF Studio can't magically populate _level0.currentRecord and break it out into fields for you. You need to call ssCore.ADO.getRows() and parse the results (according to the row format and delimiter options you provided).


Posted by mravel in SWF Studio V3 on Dec 04 2008, 03:36 pm

Can you post some code with that above comment.

I got to var return_obj = ssCore.ADO.getRows(); but how do i parse the results after that? (eg for a table that has fields ID and FName)

I've been poring over the ado2 example and dont see ssCore.ADO.getRows() used anywhere in there. The ado1 example has too many things going on in there so i couldnt figure out the parsing bit from there either.

I also tried using ssCore.ADO.getRows() best as i could understand from the forums but i still didn't get it. So few lines of code to set me in the right direction would be very much appreciated.


Posted by northcode in SWF Studio V3 on Dec 04 2008, 04:09 pm

The ADO2 example is a record oriented editor so each time the current record position is changed the current row data is sent to the onPositionChanged function and that's where it gets parsed into fields. It's a bit different from the way you're trying to do things.

The ADO1 example is more like what I believe you're trying to do, process the results of a SQL query. That example uses getRows(). It was written in Flash MX though, so everything is being done asynchronously and that makes the code a bit harder to follow.

This is a REALLY simple ADO example that just spits out the results in XML format and dumps it to the SWF Studio trace window. All you have to do is load the string into an XML document and then you can use Flash's XML support to examine the data.


ssCore.init();
ssDefaults.synchronousCommands = true;

// Set the connection string for a MS Access database using MS Jet.
// We need to specify a full path to the datasource. The database exists
// in the same folder as our application so we can use ssGlobals.ssStartDir.

ssCore.ADO.setConnectString({connectString:"Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=False; Data Source="+ssGlobals.ssStartDir+"\\example.mdb;"});

// execute an SQL query 

ssCore.ADO.setSQL({sql:"select * from [2004 Billionaires] where [rank] < 10"});

// The values set above are not used until we perform an open command,
// which will connect to the ADO provider and get a recordset.

var return_obj = ssCore.ADO.open();

if (return_obj.success)
{
    // if the open completed successfully we get all of the rows from the recordset as XML
    return_obj = ssCore.ADO.getRows();

    if (return_obj.success)
    {
        // if there were records to be returned we display them in the SWF Studio Trace tab
        ssDebug.trace(return_obj.result);
    }
    else
    {
        // if an error occurs we display the description in the SWF Studio Trace tab
        ssDebug.trace("ERROR: "+return_obj.Error.description);
    }
}
else
{
    // if an error occurs we display the description in the SWF Studio Trace tab
    ssDebug.trace("ERROR: "+return_obj.Error.description);

    // we also display the adoError output parameter for the open method, which will be
    // populated if there is an ADO-specific error message returned from the ADO provider
    ssDebug.trace(" adoError: "+return_obj.adoError);
}
I've attached a ZIP file with the FLA (Flash 8) and the example database so you can just build it and see how it works.

attachments: example.zip  


Posted by mravel in SWF Studio V3 on Dec 05 2008, 08:00 am

Thanks a lot for the code tips, it really cleared things up. Will probably upload my simple mdb examples after my project is over so hopefully other completely clueless newbies such as myself who come to the forum can learn from them :)