Solved

Extremely urgent datatable refresh

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

778 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