Inserting rows without retrieving data

Question:
I have a very large table that contains thousands of rows. I want to let a user insert new rows into it on a particular form without having to query the table. How can I create a recordset that is bound to a table and session so that I can quickly insert the row and then close the recordset?

Answer:
If you want to use a recordset to insert the row, it’s not a big effort. You can create a standalone recordset with the NEW DBRECORDSET function. You then associate an SQL query with the recordset with the SetQuery() method of the recordset, making sure to set the second parameter of the method to TRUE, which will allow the recordset to be updatable. Executing the SetQuery() method will cause a recordset to be created, with columns for each column mentioned in the SQL query, but will not populate the recordset with any columns.

After the recordset is created, you can simply use the InsertRow() method to add a row to the recordset and set the column values appropriately. Your final step will be to commit the transaction with the CommitWork() method of the session and delete the recordset.

If your session name was ORDERDAT, the table was ITEMS, and the required fields for the table were ITEM_NUMBER, DESCRIPTION and PRICE, the code to implement the above functionality would be:

DIM oRecSet AS objectoRecSet = NEW DBRECORDSET(ORDERDAT)oRecSet.SetQuery(“select ITEM_NUMBER,DESCRIPTION,PRICE from items”,true)oRecSet.InsertRow()oRecSet.SetColVal(“ITEM_NUMBER”, 99)oRecSet.SetColVal(“DESCRIPTION”, “Oh boy!”)oRecSet.SetColVal(“PRICE”,100)ORDERDAT.CommitWork()DELETE oRecSet

But you may not have to do even this much work. You could also use bound containers in a form and just set the DefaultCondition to a condition that you know will not return any rows, such as “1 = 0”. This will prevent any rows from being retrieved, while still allow you to use all the default functionality of the form to insert and commit rows.Finally, remember that Power Objects is optimized for client-server data retrieval. If you use one of the incremental fetch modes for the RowFetchMode property, only a small subset of rows will be returned to your form.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS