Recordset vs Rowset

Hi all!

I’m approaching to new 2019r2, so I have a lot of “deprecate warnings”. One of my big problem is that recordsets return an 1 based array, and rowsets return a 0 based array. In some of my projects, I have a lot of recordsets and I use idxfield(x) to use some of the fields in the query. Now I have to correct about 20.000 rows in one of my biggest app, to avoid problems in the next future.
My question is: do you know how to do this quickly without edit one row at time?

In most cases I use loops “for” to manage my query results, but in other cases I have rs.idxfield(2).value… rs.idxfield(19).datevalue… and I have a lot of probability to be in mistake correcting them manually as rs.idxfield(1).value… rs.idxfield(19).datevalue…

Thanks in advance.

Deprecated does not mean gone. Recordset is going to be around a long time. Personally, I don’t think it’s worth converting an existing project to use API 2.0 because there’s no easy way to ensure you get it right. Going from 1-based to 0-based is not a trivial matter.

FWIW, I rarely, if ever use IDXField. I prefer referring to the field by name that way it doesn’t matter what order they are and if someone (maybe even you) inserts another field in the query it doesn’t throw off IDXField. Doesn’t help your situation now but the only time I use IDXField is I am literally bringing back 1 field and 1 field only.

That’s unfortunate and I use the rs.idxfield(n).value as well, but I stopped quite a while ago because there are more problems with using that. Especially if you use something like Select * from table. If the table structure ever changes you might get back an unexpected column.

Instead I suggest using rs.Field(“FieldName”).Value, or the new rowset.column. This way you are guaranteed to get the expected value back regardless of its position in the table or recordset. If you take the time to change all of your code that reference idxfield, it might be worthwhile to change it to reference the field name, rather than the index number.

And Bob beat me to it…

Sergio, I would have thought you would have used a while not rs.EOF…rs.MoveNext…Wend loop. It is suggested we change to a for each…in…next loop, to be easier to read and no longer needs the rs.MoveNext.