?
Solved

Extremely urgent datatable refresh

Posted on 2004-09-11
3
Medium Priority
?
2,344 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 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