Skip to main content
February 10, 2013
Question

Update certain rows in datagrid from database

  • February 10, 2013
  • 1 reply
  • 721 views

Hi guys

Thanks for answering a couple of my other questions in the last day or so - I haven't got to properly going through them as I have been working on my database/datagrid interaction, and it's been all consuming.  I'm almost done, but...

...I'm wondering what the best way is to retrieve certain rows from a database, and use them to overwrite the related rows in a datagrid?

My datagrid's dataprovider looks like...

song_id, title, artist, ...

... where song_id corresponds to the song_id primary key column in my database.

Rather than repopulate the whole datagrid by selecting all the rows in the database, I'm selecting certain rows using WHERE IN ( 2, 6, 77, 999... ) in my query, and am wondering how to use to the song_id in the returned data to find the correct row to overwrite in the datagrid.

I'm unsure how to fill in the blanks...

var L = returnedDatabaseResultsArray.length;// length of array of objects returned by my WHERE IN ( 2, 6, 77, 999... )

for (var i:int = 0; i < L; i++)

{

        var _rowNumber:int = returnedArray(i).song_id;//extract song_id out of this row of returned data

        //find the row in the dataprovider that contains song_id, then (what goes here?)...

    data_grid.dataProvider.replaceItemAt( returnedDatabaseResultsArray(i), _rowNumber );// overwrite that row with this row from database

}

Cheers guys

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
February 10, 2013

what are the elements of returnedArray?

are they row contents from your datagrid?  if so, does your datagrid contain song_id?  if not (because you don't want to display it), you can add it to your datagrid and not display it.

February 10, 2013

returnedArray contains row data for all the columns in my database, which correspond exactly to my dataprovider.

song_id is not displayed in the datagrid, but is in the dataprovider, and sorresponds with the song_id PK in the database

To make it a little clearer, when I'm booting up the app, I select ALL the rows from my database, and populate my dataprovider with the results like this...

function onSelected(evt:SQLResult):void

        {

            if (evt.data != null)

            {

                data_grid.dataProvider = new DataProvider(evt.data);   //{song_id:1212, Title:"Unbreakable", Artist:"Tough Guy".. etc}            

            }

            conn.close();

        }

What I'm looking for now is a way to load specific rows from the database, and, using their song_id property, overwrite the corresponding rows in the datagrid.

Thanks for you help Keith

kglad
Community Expert
Community Expert
February 10, 2013

i still don't understand.

you have a list of song_id's and you want to query the database to return the title,artist corresponding to those song_id's and then use those data to populate a datagrid?

if so, what's the problem?  do you want to do that without querying the database by using the already returned data of all song_id's and their corresponding title,artist?