Refreshing Datagrid

dobbs
10-27-2004, 10:27 AM
I have a form that utilizes a MapControl property to add GIS point data. I also have a datagrid that is displaying the table associated with that point data via ADO. When I add a point the data is stored in the database but the data is not updated within the datagrid until the next time I call the actions of the 'Add Point' tool. I am sure this is a requerying issue with my datagrid not querying the database again during my sub. Can anyone help? I would appreciate any help someone could provide!

Thanks in advance! :huh:

loquin
10-27-2004, 11:53 AM
try requerying the underlying recordset.

dobbs
10-29-2004, 09:14 AM
I do requery the underlying recordset by calling this line of code:

adoNotes.Recordset.Requery

Is the correct approach?

try requerying the underlying recordset.

Dennis DVR
10-29-2004, 09:28 AM
I do requery the underlying recordset by calling this line of code:

adoNotes.Recordset.Requery

Is the correct approach?

How about calling the the Rebind method of datagrid? if still didn't work, then reset the grid's datasource to nothing and set its datasource again to adoNotes.

Note: Doing the above method will reset the column heading.

dobbs
10-29-2004, 10:11 AM
I have tried calling the rebind method of datagrid by setting this code:

dgdNotes.ReBind

But it does not work. When I try setting the datasource to nothing and resetting it to my adoNotes, it does the same thing:

Set dgdNotes.DataSource = Nothing
Set dgdNotes.DataSource = adoNotes

Any ideas?

How about calling the the Rebind method of datagrid? if still didn't work, then reset the grid's datasource to nothing and set its datasource again to adoNotes.

Note: Doing the above method will reset the column heading.

Dennis DVR
10-29-2004, 11:22 AM
then the problem is not in the grid control but in your recordset.

try adding DoEvents after the saving process, but I would suggest to post your code, so we can have a look and see where the problem is.

dobbs
10-29-2004, 12:44 PM
How would I go about adding DoEvents? Here is my code:


Set pAv = MapControl1.Map
Dim pPt As IPoint
Set pPt = New Point
pPt.PutCoords mapX, mapY
Dim pFeatCur As IFeatureCursor
Set pFeatCur = pEditFeatureClass.Insert(True)
Dim pFeatBuff As IFeatureBuffer
Set pFeatBuff = pEditFeatureClass.CreateFeatureBuffer
Set pFeatBuff.Shape = pPt
Dim strName As String

'set the attributes
pFeatBuff.Value(pFeatBuff.Fields.FindField("floor_id")) = "" & txtFloor.Text
strName = InputBox("Enter value for description column")

'set the attributes
pFeatBuff.Value(pFeatBuff.Fields.FindField("description")) = "" & strName
pFeatCur.InsertFeature pFeatBuff

'Refresh MapControl
MapControl1.Refresh

'Update newly added fields to notes layer
adoNotes.Recordset.Requery

dgdNotes.ReBind

Set dgdNotes.DataSource = Nothing
Set dgdNotes.DataSource = adoNotes


Just a note, I am calling this code on a toolbar that is activated when the button is pressed.

then the problem is not in the grid control but in your recordset.

try adding DoEvents after the saving process, but I would suggest to post your code, so we can have a look and see where the problem is.

Dennis DVR
10-29-2004, 01:00 PM
I don't see where the adoNote recordset is being updated, you should call the Update or Updatebatch before calling the requery, and you should not use both Rebind and Set dgdNotes.DataSource = adoNotes.

Ok, first lets forget about the DoEvents. Call the Update or UpdateBatch before calling the Requery method.

adoNotes.Recordset.UpdateBatch


and remove this three lines

dgdNotes.ReBind

Set dgdNotes.DataSource = Nothing
Set dgdNotes.DataSource = adoNotes


If that method doesn't work, then put back the

Set dgdNotes.DataSource = Nothing
Set dgdNotes.DataSource = adoNotes


If still doesn't work

adoNotes.Recordset.UpdateBatch
adoNotes.Recordset.Requery

or

adoNotes.Recordset.UpdateBatch
DoEvents

dobbs
10-29-2004, 02:20 PM
Thanks for you help! It works if I put a message box between each line of code. It is like it needs a pause to update the table. Can I add a pause automatically without popping up a message box?

I don't see where the adoNote recordset is being updated, you should call the Update or Updatebatch before calling the requery, and you should not use both Rebind and Set dgdNotes.DataSource = adoNotes.

Ok, first lets forget about the DoEvents. Call the Update or UpdateBatch before calling the Requery method.

adoNotes.Recordset.UpdateBatch


and remove this three lines

dgdNotes.ReBind

Set dgdNotes.DataSource = Nothing
Set dgdNotes.DataSource = adoNotes


If that method doesn't work, then put back the

Set dgdNotes.DataSource = Nothing
Set dgdNotes.DataSource = adoNotes


If still doesn't work

adoNotes.Recordset.UpdateBatch
adoNotes.Recordset.Requery

or

adoNotes.Recordset.UpdateBatch
DoEvents

MKoslof
10-29-2004, 05:33 PM
That is the purpose of DoEvents :). You could implement the sleep API call, but be warned, this pauses ALL running processes, so if your table is still updating, this will also pause, so it may not help.

May I ask where you define adoNotes? Where is this defined and initialized?

Typically, when a problem like this occurs, the best answer to restructure the code so that this stops occuring. There is some processing lag in your code..we just need to find where it is.

dobbs
11-01-2004, 02:20 PM
Thanks for the response!

I have my ado connection setup within the form, not in the code. Show I set up the ado programmatically instead? Could this be why I am getting the lag?

That is the purpose of DoEvents :). You could implement the sleep API call, but be warned, this pauses ALL running processes, so if your table is still updating, this will also pause, so it may not help.

May I ask where you define adoNotes? Where is this defined and initialized?

Typically, when a problem like this occurs, the best answer to restructure the code so that this stops occuring. There is some processing lag in your code..we just need to find where it is.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum