Hi David,
At run time, you can just run the command of the dataenvironment to refresh
the contents. In fact, the command object is regarded as a function of the
dataenvironment and can be ran when needed. In the situation you described,
after changing the dataenvironment connectionstring and so the refered
database is changed, we need to run the command to apply the changes .
Please refer to the following example.
In this example, I have two buttons to change the back end database of an
dataenvironment between SQL server and Access database each, and then
populate an datagrid control with the data from one of the tables in each
database.
Below is the code corresponding to each button_click event:
Private Sub Command1_Click()
DataEnvironment1.Connection1.Close
DataEnvironment1.Connection1.ConnectionString =
"Provider=SQLOLEDB;Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=pubs;Data Source=chris2000"
DataEnvironment1.Connection1.Open
DataEnvironment1.Commands(1).CommandText = "dbo.TABLE1"
DataEnvironment1.Command1 'This line is the key point.
DataGrid1.DataMember = "command1"
End Sub
Private Sub Command2_Click()
DataEnvironment1.Connection1.Close
DataEnvironment1.Connection1.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\My
Documents\TEMP\Db1.mdb;Persist Security Info=False"
DataEnvironment1.Connection1.Open
DataEnvironment1.Commands(1).CommandText = "table1"
DataEnvironment1.Command1 'This line is the key point.
DataGrid1.DataMember = "command1"
End Sub
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. Copy right, 2001 Microsoft Corporation.
All rights reserved.
Chris
Microsoft Support