ASP Database RecordSet

[Total: 0    Average: 0/5]

The Recordset Object

We’ve used the recordset object in the last tutorial when we added a user to our users table in our database. However, we did not go into any real detail about the recordset object. So, let’s first talk about what the recordset object is.

What is the recordset object?

The recordset object is an ADO (Active Data Objects) object. It is the collection of rows from a data source. So when you connect to a table in your database, your recordset object houses the rows of data from that table. When you work with your recordset, there are different things you can do with it. You can use it to add a new record (as you’ve seen in the last tutorial), update a record, delete a record, or simply display records on your pages. This is why ASP is so great to work with. By using the recordset object, you can dynamically insert data into your pages based on the criteria sent to the page by the user. The data is then pulled from the data base, translated to HTML and inserted in your page.

How does the recordset object work?

Well, there is a certain syntax for the opening a recordset object. First you must create an instance of the object. The syntax to do this is:

Next you need to open your recordset. The syntax for opening a recordset is as follows:

What’s happening here is:

First we specify our table name to open with our recordset object
Secondly, we open our connection to our table using our objConn from our connection.asp page
Thirdly, we specify the cursor type. This is a lesson in and of itself, so we won’t go into cursors right now.
Fourthly, we specify that we want a lock type of Pessimistic. This insures that if another user happens to be adding information to the database at the same time, that the database will be locked before our information is added. This keeps the database updated and keeps 2 records from being added simultaneously which could cause a problem. This also keeps other users from accessing the data from the records until the update method is called and the record has been added successfully.
Lastly, we specify what kind of source we’re using if it’s not a command object.
That’s it for now. This should give you a pretty good understanding of the recordset object. More information will be coming in the future about the Cursor Type and different ways to use it depending on the job your doing.

~Geoff Swartz

Times Viewed: 9

Leave a Reply

Your email address will not be published. Required fields are marked *