Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to refresh DataGrid Control when updating the Database?

Posted on 2002-06-03
12
Medium Priority
?
163 Views
Last Modified: 2011-10-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

    adoBooks.Refresh
    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()
     adoBooks.Refresh
     grd2Books.Refresh
    End Sub

and when I click the ButtonBox, the datas in the Grid are refreshed.
   Can Someone tell me what's the matter?
0
Comment
Question by:Iaskyou
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7050613
Try to use
Doevents
between the .Execute and the .Refresh...
I guess that your Refresh comes toooooo fast :-)

CHeers
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7051217
Are you using only 1 connection? You won't get problems this way.

Have a look at
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q200300
http://www.experts-exchange.com/questions/Q_20237490.html
0
 

Author Comment

by:Iaskyou
ID: 7058743
I use two Connection. One is ADODB.Connection Object, the other is ADODC. The question is that The first
time I change the data, the grid doesn't refresh at all. But if I change the data again, the grid will
show the data which I changed the first time. and the third time the second-time data is showed. why?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7058875
Don't connect through ADODC. Use only one connection. You don't need an ADODC to use a grid. You can simply open a static recordset and bind it to the grid this way:

set datagrid1.datasource = YourRecordset

If you absolutely want to keep your ADODC, your will need to refresh your connections (see the links of my previous post).

>>show the data which I changed the first time. and the third time the second-time data is showed. why?

This is because Access is not a real database engine. It is only a file sharing manager!
0
 

Author Comment

by:Iaskyou
ID: 7060875
I have solved this question. Only add "BeginTrans" and "CommitTrans" can OK. Thanks for all of you.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7060881
you can't leave this question opened. please ask CS to refund your points and move this question to PAQ (or delete it)
0
 

Expert Comment

by:Audsimous
ID: 7155117
simply add this line after your refreshes...

set grd2Books.datasource = adobooks
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7157984
Audsimous, haven't you read that Iaskyou solved his problem?
0
 
LVL 1

Expert Comment

by:kodiakbear
ID: 7522858
Dear Audsimous
I've rejected your proposed answer as Experts Exchange holds an experiment to work without the answer button.

See: <http://www.experts-exchange.com/jsp/communityNews.jsp>
Paragraph: Site Update for Wednesday, November 06, 2002

By this rejection the Asker will be notified by mail and hopefully he will take his responsibility to finalize the question or post an additional comment.
The Asker sees a button beside every post which says "Accept This Comment As Answer" (including rejected answers) -- so if he/she thinks yours is the best, you'll be awarded the points and the grade.

EXPERTS: I will return in seven days to close this question.
Please leave your thoughts and recommendations here

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Thanks !

kodiakbear
Experts Exchange Moderator
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7523502
refund and move to PAQ
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7851416
Hi Iaskyou,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.
    *** even though emoreau's suggestion to avoid ADODC is the best solution -- a real winner

Iaskyou, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 7912926
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question