CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 35
  1. #1
    Join Date
    Jun 2009
    Posts
    10

    Refresh Database

    i have a problem and it's hard to explain but don't know the solution for many years,pls help me...

    A is viewing database from datagrid.
    after that
    B inserting a new data to database from different computer.
    A still looking datagrid from database before updated.

    if he don't click refresh or using timer how can the datagrid automatically refresh the data from database without using button or timer.
    i don't like using timer cause it eat resources a lot.

    thx
    sorry bad english

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Refresh Database

    User B cannot EDIT a record in that table, because it cannot get a LOCK without refreshing first.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Refresh Database

    That depends on the connection methods, it is totally possible for user A to be viewing data in a grid and user B edit the data or insert a record on a different machine. User A will not see the edit or insert until a refresh is done at user A's location.

    A timer is the best solution I can think of, if used right a timer takes very little resources

  4. #4
    Join Date
    Jun 2009
    Posts
    10

    Re: Refresh Database

    i am afraid timer can make problem too.
    example :
    a grid display 100 row with vertical scroll. the user is looking at row 90
    because i am using timer the grid is refreshing every interval 1 second ( i make 1 second timer refresh) so the scroll is always at top position.it make user hard to see the grid
    is there any solution?



    User B cannot EDIT a record in that table, because it cannot get a LOCK without refreshing first.

    sorry i don't really understand it,do u mean i must lock the database if anyone see the grid

    thx

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Refresh Database

    I would not recommend actually refreshing the data every second but rather create a routine to see if the data has changed. I am not sure if there is a method in dot net for this or not but I am sure there is a way especially if the other user is using your program as well.

    I have a program that does refresh the data in a timer routine written in vb6. The way I got around the display issues was by using a second grid. When I refresh I refresh the second [invisible] grid, move the record pointer and then display the second grid and hide the first. This prevents screen flicker and speeds up the process of populating the grid as well. Works good in this case but the data being used is not usually more than a couple of hundred records.
    .

  6. #6
    Join Date
    Jun 2009
    Posts
    10

    Re: Refresh Database

    Quote Originally Posted by DataMiser View Post
    I would not recommend actually refreshing the data every second but rather create a routine to see if the data has changed. I am not sure if there is a method in dot net for this or not but I am sure there is a way especially if the other user is using your program as well.

    I have a program that does refresh the data in a timer routine written in vb6. The way I got around the display issues was by using a second grid. When I refresh I refresh the second [invisible] grid, move the record pointer and then display the second grid and hide the first. This prevents screen flicker and speeds up the process of populating the grid as well. Works good in this case but the data being used is not usually more than a couple of hundred records.
    .
    i think that's not really effective ways cause my data is more than hundred records.
    i heard about using threading but i don't really understand how to use it

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Refresh Database

    If you let the DB LOCK the record, then user B can't edit it. Please wait...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Refresh Database

    Quote Originally Posted by RusdyRIP View Post
    i think that's not really effective ways cause my data is more than hundred records.
    i heard about using threading but i don't really understand how to use it
    I understand, and as I said it is probably not a good idea to refresh in a timer every n miliseconds but rather place some code in a timer to see if the data has changed and only when this is true do a refresh. This should nto be an issue other than the fact you will need to determine if the data has changed.

    Of course you could lock the database and not allow anyone to edit it but in most cases that is not much of an option.

  9. #9
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Refresh Database

    Quote Originally Posted by dglienna View Post
    If you let the DB LOCK the record, then user B can't edit it. Please wait...
    Note in the OP he was refering to another user inserting a record so locking the record you are viewing would have no effect.

  10. #10
    Join Date
    Jun 2009
    Posts
    10

    Re: Refresh Database

    Quote Originally Posted by DataMiser View Post
    Note in the OP he was refering to another user inserting a record so locking the record you are viewing would have no effect.
    yes,i think same too.if 2 user editing same record then it will have effect,but the problem is on grid report,thx

    if i make a routine that check any changes on database,
    i am afraid the server CPU Usage will raise,
    if i make the routine then it will gonna check every second,if it have changes then it will refresh.
    but if it don't have changes then it will gonna check to server.
    if just one user i think it don't really will raise the cpu usage on server,but how about
    if there is 5 user connecting and see the grid on 5 cpu,or every cpu open 5 report grid.
    i think it will raise the cpu usage on server and can make the server crash.

    thx

    sorry bad english

  11. #11
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Refresh Database

    Just LOCK the table when it EDIT mode, and you won't have a problem.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  12. #12
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Refresh Database

    I didn't see a mention of which database you're using, but if you are using for MS SQL Server 2005 or later, you have access to the SQLDependency which can notify clients when changes occur in the database.
    I'd suspect other databases might have similar technologies.

    But this way you can set up a dependency to the data being viewed, and when they change the notification will fire an event and you can then refresh the data for the other viewers based on the edit.

  13. #13
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Refresh Database

    Quote Originally Posted by dglienna View Post
    Just LOCK the table when it EDIT mode, and you won't have a problem.
    I do not understand how this could relate to the issue of wanting to refresh the view on the pc which is viewing the data that may have been added to or edited at another location? It the other pc locks the data for edit that is fine but that does not refresh the views on other pcs.

  14. #14
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Refresh Database

    Quote Originally Posted by RusdyRIP View Post
    yes,i think same too.if 2 user editing same record then it will have effect,but the problem is on grid report,thx

    if i make a routine that check any changes on database,
    i am afraid the server CPU Usage will raise,
    if i make the routine then it will gonna check every second,if it have changes then it will refresh.
    but if it don't have changes then it will gonna check to server.
    if just one user i think it don't really will raise the cpu usage on server,but how about
    if there is 5 user connecting and see the grid on 5 cpu,or every cpu open 5 report grid.
    i think it will raise the cpu usage on server and can make the server crash.

    thx

    sorry bad english
    Not sure what you are thinking here, no need for 5 grids.

  15. #15
    Join Date
    Jun 2009
    Posts
    10

    Re: Refresh Database

    Quote Originally Posted by DataMiser View Post
    Not sure what you are thinking here, no need for 5 grids.
    sory, i mean like this
    i have application which using tab pages.
    so user can show like 5 report/grid report.
    if i use the check database method then i think the server will overload cause
    the timer always send check routine and the 5 tab pages opened by user also make 5 timer and 5 check routine.
    it will make server cpu usage rise.
    thx

    @Alsvha

    i am using firebird database.may i know what the "name" of that dependancy.
    so i can search the feature of the database.cause i think it will work
    thx

    @dglienna
    i think i have same opinion like DataMiser,i don't really think it related
    thx

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured