Solved

Extremely urgent datatable refresh

Posted on 2004-09-11
3
2,341 Views
Last Modified: 2012-06-27
Hi Experts!

I have a server with a SQL server database.   This database contains our live trades for the day, updated in real time.  The size of the table is very small (like a few hundred rows only).

The client machine has a datatable of these trades which loads fine using dataAdapter.Fill.  I want the client datatable to be updated in real time.  

If I call the fill again it doens't work, and I cannot clear the table, just make changes to it to make sure they are in-sync.

What is the best way to do this over the LAN?  Keep in mind I would like this to work as real-time as posssible, however a small delay could be tolerable.

Should i create a second datatable, have it constantly clear and fill on a timer and run code to update one row at a time?  or is there an easier way?

Thanks!!!

0
Comment
Question by:OptionsMM
[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
3 Comments
 
LVL 5

Accepted Solution

by:
tomasX2 earned 500 total points
ID: 12035718
You could use a merge...

DataSet latestData = GetLatestData();  // dataAdapter.Fill
clientData.Merge(latestData ,true,System.Data.MissingSchemaAction.Add);

//primary key
clientData.Tables[0].PrimaryKey = new DataColumn[]{clientData.Tables[0].Columns["ID"]};


this would work if the dataset has a primary key on the trades table and the data is inserted and updated only... not deleted... because the deleted rows would not be present in the lastestData and would not get deleted in the clientData dataset..

if you want to get rid of the deleted rows you could loop through the new clientData and check if the row exists in the latestData
To get rid of the deleted rows...
                        System.Collections.Specialized.StringCollection col = new System.Collections.Specialized.StringCollection();

                        foreach( DataRow row in clientData.Tables[0].Rows )
                        {
                              if( latestData.Tables[0].Rows.Select("ID='" + row["ID"].ToString() + "'").Length == 0 )
                              {
                                                                                                // Add to the collection of rows to be deleted.....
                                    col.Add(row["ID"].ToString());
                              }
                        }

                        foreach( string id in col )
                        {
                              clientData.Tables[0].Rows.Find(id).Delete();                              
                        }



0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 12036751
Hi,

Look at this example, it may help you to sort your problem..
http://www.akadia.com/services/dotnet_update_form.html

R.K
0
 
LVL 4

Expert Comment

by:Jigit
ID: 12037354
I can suggest usage of locks: when a row(record) is being opened for editing it must be locked in the database. When it's being saved the changes are immidiately updated in the database and the lock is removed. When user searches some row by some criterias, there will be access to the database. It this approach, there will be a little bit more accesses to the SQL server, but there will be two main advantages: 1) the data is always synced and up-to-date, 2) there will never be collision between two different client users updating the same record. You said that database volume is not big, so the overhead will be acceptable.

HTH,
Jigit
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 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