CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2001
    Location
    India
    Posts
    13

    Changing Recordsource at run-time

    This is about DataGrid and ADO Control.
    I have set RecordSource and datasource property at design time.
    However I want to change the RecordSource at run time also.
    Say My Screen is showing sales plan of a particular product. I have a ComboBox on screen and I want that as soon as user selects a product the datagrid should be populated by sales plan of that product. This is how I have implemented it.

    Private Sub cbProduct_Validate(Cancel As Boolean)

    Dim prod_table As String
    prod_table = cbProduct.Text & "_SP"
    sqlstr = "select * from " & prod_table & " order by warehouse_id "
    rs.Close
    rs.Open (sqlstr)
    Set Adodc1.Recordset = rs
    DataGrid1.Refresh

    End Sub

    But this is not working. Can you tell me what the problem is ?


  2. #2
    Join Date
    Apr 2001
    Posts
    3

    Re: Changing Recordsource at run-time

    You need to refresh your data control

    'adodc1.refresh' after changing the recordset


  3. #3
    Join Date
    Apr 2001
    Location
    India
    Posts
    13

    Re: Changing Recordsource at run-time

    I tried doing Adodc1.Refresh also. What is happening is I am getting zero records in the data grid after changing the recordset.
    Anything else that I am missing ?


  4. #4
    Join Date
    Apr 2001
    Location
    India
    Posts
    13

    Re: Changing Recordsource at run-time

    This is how it has worked finally :

    sql = "Select ......"
    Adodc1.RecordSource = sql
    Adodc1.Refresh




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