• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

How to refresh DataGrid Control when updating the Database?

  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()
    End Sub

and when I click the ButtonBox, the datas in the Grid are refreshed.
   Can Someone tell me what's the matter?
1 Solution
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Try to use
between the .Execute and the .Refresh...
I guess that your Refresh comes toooooo fast :-)

Éric MoreauSenior .Net ConsultantCommented:
Are you using only 1 connection? You won't get problems this way.

Have a look at
IaskyouAuthor Commented:
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?
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Éric MoreauSenior .Net ConsultantCommented:
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!
IaskyouAuthor Commented:
I have solved this question. Only add "BeginTrans" and "CommitTrans" can OK. Thanks for all of you.
Éric MoreauSenior .Net ConsultantCommented:
you can't leave this question opened. please ask CS to refund your points and move this question to PAQ (or delete it)
simply add this line after your refreshes...

set grd2Books.datasource = adobooks
Éric MoreauSenior .Net ConsultantCommented:
Audsimous, haven't you read that Iaskyou solved his problem?
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


Thanks !

Experts Exchange Moderator
Éric MoreauSenior .Net ConsultantCommented:
refund and move to PAQ
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
per recommendation

Community Support Moderator @Experts Exchange
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now