How to refresh DataGrid Control when updating the Database?
Posted on 2002-06-03
I use an DataGrid Control and the datasource is set as the name of an ADODC Control.The datas showed at the DataGrid are from several tables. After modifying the datas of one of these tables by SQL through ADODB.Connection.Execute method, I always refresh the ADODC control and the DataGrid control by the "refresh" method of both controls. To my suprised, the datas in the DataGrid are not changed at all. Why? that below are codes:
lngBookID = adoBooks.Recordset(0) 'adoBooks is ADODC
strSql = "update books set BookName='" & txt2ShowBookName.Text Where BookID = " & CStr(lngBookID)
gblDBConn.Execute strSql 'gblDBConn is ADODB.Connection
grd2Books.Refresh 'grd2Books is DataGrid Control
What puzzled me is that if I write the Refresh Codes in the Click Event Sub of ButtonBox like that:
Private Sub Command1_Click()
and when I click the ButtonBox, the datas in the Grid are refreshed.
Can Someone tell me what's the matter?