Link to home
Start Free TrialLog in
Avatar of bhlang
bhlangFlag for Canada

asked on

Refreshing a DataGrid from a DataEnvironment Recordset

I have a DataEnvironment set up and working. I can load the recordset into the DataGrid. Now I want to be able to change the data in the DataGrid. The user selects a menu which changes the SQL statement controlling the recordset behind the DataGrid (The DataSource and DataMember of the DataGrid). I cannot find any way of refreshing the data in the DataGrid.

My Code for one of the menu selections:

    strQuery = "SELECT MNAME, MCO, MADDR, MSTRT, MCITY, MPROV, MCNTRY, MPO1, MPO2, " & _
        "MGROUP, MID FROM " & coLib & "DT.DTNAME Order By MNAME, MCO"
    frmLoad.Show
    frmLoad.Refresh
    deAddresses.Commands(1).CommandText = strQuery
    deAddresses.rsqryDTNAME.Close
    deAddresses.qryDTNAME
    DataGrid1.ReBind
    DataGrid1.Refresh
    Me.Refresh
    Unload frmLoad


I know the query is good, because the only difference between this SQL statement and the initial SQL statement is the Order By clause. The problem is that I cannot get the damn DataGrid to refresh with the new data. However if I select a row in the DataGrid and load it into the editor I've setup I do not get the record shown on the screen. I get the record I'm supposed to get based on the new query. Any help would be appreciated ASAP!
Avatar of AzraSound
AzraSound
Flag of United States of America image

set the grids datasource to your new recordset

set datagrid1.datasource = newrs
Avatar of GivenRandy
GivenRandy

Have you upgraded to Visual Studio Service Pack 3?  This fixed object problems like this.
Avatar of bhlang

ASKER

I am using VB6 SP3.

I have tried setting the DataSource. The problem is not the DataSource, it is the DataMember. When using a DataEnvironment, you set up a Connection (DataSource) and a Command (DataMember). You can have multiple Commands set up under a connection. You can have multiple Connections set up in a DataEnvironment.
To set the DataMember I use the following:

Set DataGrid1.DataMember = deAddresses.rsqryDTNAME
(The command is called qryDTNAME and the DataEnvironment creates the recordset rsqryDTNAME)

Which gives me the following:

Compile error: Wrong number of arguments or invalid property assignment


ASKER CERTIFIED SOLUTION
Avatar of wsh2
wsh2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bhlang

ASKER

That did the trick. If I had read the VB Help files better, I would have seen this in the example for DataMember. Thank you for your prompt reply. Thank you everyone else for your assistance also.