Solved

Extremely urgent datatable refresh

Posted on 2004-09-11
3
2,338 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now