CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Posts
    15

    URGENT!!!! Adding columns to a recordset

    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


  2. #2
    Join Date
    Aug 1999
    Location
    India, TamilNadu, Chennai.
    Posts
    269

    Re: URGENT!!!! Adding columns to a recordset

    hi friend,

    Tell which data control you are using, DAO, ADO
    with more details.

    [email protected]
    Babu


    MailID: [email protected]
    Please avoid sending emails to my personal mail:
    write your doubts as thread in Codeguru
    Crystal Reports Forum
    .

    This will help all people having similar matters, and will let people who know solutions on the specific topic
    share their knowledge.

    Visit my company web site (Qmax Test Equipments Private Limited)

    Yours friendly,
    K.Babu

  3. #3
    Join Date
    May 1999
    Posts
    15

    Re: URGENT!!!! Adding columns to a recordset

    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



  4. #4
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329

    Re: URGENT!!!! Adding columns to a recordset

    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.

    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

  5. #5
    Join Date
    Aug 1999
    Location
    India, TamilNadu, Chennai.
    Posts
    269

    Re: URGENT!!!! Adding columns to a recordset

    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: [email protected]
    Please avoid sending emails to my personal mail:
    write your doubts as thread in Codeguru
    Crystal Reports Forum
    .

    This will help all people having similar matters, and will let people who know solutions on the specific topic
    share their knowledge.

    Visit my company web site (Qmax Test Equipments Private Limited)

    Yours friendly,
    K.Babu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured