Click to See Complete Forum and Search --> : URGENT!!!! Adding columns to a recordset
Purnima
April 27th, 2001, 04:44 AM
Hi,
Please treat this as urgent.
How do I add columns to an already populated recordset? If I create a blank recordset and then add columns to it from scratch, it works however, if I try to add columns to a recordset which is picked up from a database, it throws an error. Is it a limitation or a problem? Any workaround anyone can suggest? I would appreciate any pointer in this direction. Thanks in advance.
Regards,
Purnima
K.Babu
April 27th, 2001, 05:01 AM
hi friend,
Tell which data control you are using, DAO, ADO
with more details.
k_babs@hotmail.com
Babu
MailID: k_babs@hotmail.com
Purnima
April 27th, 2001, 05:33 AM
Hello Babu,
Thanks for the reply.
I'm using ADO for the same.
If I use -
Set rs = New ADODB.Recordset
rs.Fields.Append "Col1", adInteger
It works. The requirement is that the recordset should not be open and should not be connected to a datasource.
I tried by setting the ActiveConnection to Nothing, however, if the recordset already has some fields and values fetched from a database, it doesn't add a column to the recordset.
Any ideas??
Thanks again.
Regards,
Purnima
TimCottee
April 27th, 2001, 08:05 AM
purnima, you CANNOT add fields to an already open recordset under any circumstances. The general method is to create dummy fields in the recordset by appending them to the SQL statement used to generate the recordset in the first place.
Other alternatives would be to create a new recordset object in code (with the extra fields) and append the records from the query row by row into this new recordset. You could also save off the recordset as XML and use an XML parser to add the additional fields in the XML file. You can then re-open the XML file into a recordset with the new fields.
K.Babu
April 30th, 2001, 01:19 AM
Hi Friend,
Sorry, for the delay reply.
"The requirement is that the recordset should not be open and should not be connected to a datasource. I tried by setting the ActiveConnection to Nothing"
I assumed u don't need to connect or execute after the new column added once. In that case you can check the number of columns in the record set column count,
if the column name already exist in the recordset don't add the new column
else you add the new column what you need.
suppose if you don't know the column name what you added newly last, count the number of columns the record set, if the column greater than normal column count don't add the new column.
reply me your problem sloved or not!!
Babu.
MailID: k_babs@hotmail.com
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.