Solved

Extremely urgent datatable refresh

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
LINQ question 7 22
Hide Tab Page 3 20
Long URL in SMS 6 24
Access properties in nested observable collections 8 10
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

11 Experts available now in Live!

Get 1:1 Help Now