John Burtt
asked this on Jun 02 13:47
I'm just trying to begin learning SQL Yoga (and SQL). I've successfully connected to my database on my ISP server. But, there is nothing there at this time. I have a rev stack with a datagrid containing about 500 records. I have no idea how to get an array from that datagrid into my database. Can I do it all at once as an array, or do I need to do it one record at a time? Can someone please start me in the right direction? As I said before, I'm totally new to using any kind of database and SQL Yoga.

Hi John,
The simplest way is going to be to sqlquery_create. You can loop through the Data Grid array and perform the insert for each record.
Take a look at this lesson on exporting data from a Data Grid: http://lessons.runrev.com/spaces/lessons/manuals/datagrid/lessons/7...
In the repeat loop make the call to sqlquery_create:
repeat for each item theIndex in theIndexes
put theDataA[theIndex] into theRecordA ## get array for 1 record from data grid
sqlquery_create "Name of Table", theRecordA ## insert into the database.
end repeat
The above assumes that each row in your data grid only has values in it that match fields in your table.
Let me know if you need additional info or clarification on anything.

As I said before, I'm new at this.
I tried this and got an error that the table or template does not exist. Okay.
So I created a table by using: tableobj_createObject "studentData","table"
Now, I confirmed that the table exists by checking: tableobjects_tableExists("studentData")
But I'm still getting an error when I try to put data into it. I'm missing something??

It sounds like SQL Yoga hasn't imported a database schema yet as it can't find the table. You don't need to create an actual table object to use sqlquery_create.
Since you've already connected to the database you can use the SQL Yoga plugin to update the db schema. Here are the instructions:
http://revolution.screenstepslive.com/spaces/revolution/manuals/sql...
After you follow the above instructions you should be able to see your table listed in the plugin on the Properties tab. Try executing the code again and see if it works.

Hi Trevor.
Just to let you know, I was not able to add the table using SQL Yoga. I'm not sure what the problem was (probably me). But I downloaded a helper application called "Navicat" and was able to create the table using it. Once the table was created, I'm now able to use SQL Yoga to manipulate the records.
Thanks a lot for your help and quick response. I have some new questions, but I will start a new thread with them.

SQL Yoga doesn't actually create tables in the database for you (yet). So if the table didn't already exist in the database then that explains why things weren't working.
Table objects are objects within Rev so when you create one the object just exists in Rev. You can read more about table objects starting with this lesson in the manual:
http://revolution.screenstepslive.com/spaces/revolution/manuals/sql...