CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 1999
    Location
    Boston, USA
    Posts
    31

    How can a record set be used to populate a dbgrid control.

    How can a record set be used to populate a dbgrid control.

    My code is
    Dim rs As Recordset
    Dim db As Database
    ...
    ...
    Set rs = db.OpenRecordset(strQuery, dbOpenDynaset)

    I need to display the records returned in rs onto the grid???



    Regards
    Aswin Asokan

  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: How can a record set be used to populate a dbgrid control.

    Set the datasource property of the grid equal to the recordset:


    Dim rs as Recordset
    Dim db as Database
    ...
    ...
    set rs = db.OpenRecordset(strQuery, dbOpenDynaset)

    set DBGrid1.DataSource = rs
    DBGrid1.Refresh




    i'm pretty sure you can do that with DAO.

    Hope this helps,

    John

    John Pirkey
    MCSD
    http://www.ShallowWaterSystems.com
    http://www.stlvbug.org
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Join Date
    Dec 1999
    Location
    Boston, USA
    Posts
    31

    Re: How can a record set be used to populate a dbgrid control.

    set DBGrid1.DataSource = rs
    gives an error on that line

    Run-time error '430':
    Class does not support Automation or does not support expected interface

    Regards
    Aswin Asokan

  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: How can a record set be used to populate a dbgrid control.

    you cannot directly assign anything useful to the datasource property.
    But, you can use a data control and bindn your dbgrid to the data control.
    Then, if "c" is your data control and "d" is your dbgrid:

    Set rs = c.Database.OpenRecordset("select * from yourtable")
    ' assign to the recordset property OF THE DATA CONTROL
    ' this will automatically populate the DBGrid, because it's bound to the data control.
    Set c.Recordset = rs



  5. #5
    Join Date
    Dec 1999
    Location
    Boston, USA
    Posts
    31

    Re: How can a record set be used to populate a dbgrid control.

    The code gave run time error :
    Run-time error '91'
    Object variable or With block variable not set

    dataCall is a data control
    gridResults is a dbgrid

    Dim rs As Recordset
    Set rs = dataCall.Database.OpenRecordset(strQuery) 'run time error
    Set dataCall.Recordset = rs

    I also tried
    Dim db As Database
    Dim rs As Recordset
    Set rs = db.OpenRecordset(strQuery, dbOpenDynaset) 'run time error
    Set dataCall.Recordset = rs

    which again gave the same error

    Regards
    Aswin Asokan

  6. #6
    Join Date
    May 1999
    Posts
    3,332

    Re: How can a record set be used to populate a dbgrid control.

    well, your datacall object must have been initialised before you can apply a method like OpenRecordset to it.
    Set the connect property and call the Refresh method before doing anything else.


  7. #7
    Join Date
    Dec 1999
    Location
    Boston, USA
    Posts
    31

    Re: How can a record set be used to populate a dbgrid control.

    Yes, that way it works
    Thanx

    Also which is the best way to clear the records from a dbgrid control.

    Regards
    Aswin Asokan

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