5:18 pm
0
656
views

Delete a record from a ColdFusion query

Firstly, I found this method out from Ben Nadel, and it is a very useful method as well.

Ever since I can remember, if I wanted to delete a record from a ColdFusion query (queryNew()) I would have to go around the houses. For example, I would loop and rebuild the query, whilst omitting the row I want to delete, not ideal!

Well with this new found function (part of the Java object it sits on), as long as you have the row index you can remove it very easily. For example, if I know that row 4, in my 10 row ColdFusion query is the one I wish to remove, I would do the below:

<cfset local.query.RemoveRows(4,1) />

This functions format is RemoveRows(rowNumber,rowCount). So in the above, I am saying, starting at row 4, delete 1 record from my ColdFusion query local.query. Simple, yet very effective!