If Server A and Client B are chatting through sockets, and Client B requests a dataset of all accounts on the server it has access to, the server provides that data set to the client (through serialization and sending it over the socket) and the client modifys the data, say it changes a contact name or address or whatever on one or many different records, and sends the dataset back to the server so that the server can update it's records...is there a built-in method to compare the two datasets and perform those updates on the parent data source?

Check out this diagram for what I mean:

Server A		| Client B		|
-------------------------------------------------
MS Access DB File	<= Gimmie data!
DataSet with Data	=> Modify the data
MS Access DB File	<= Save my changes
Okay! All saved!	=> :) [Smiley Face]

That's the general idea, but I'm trying to get the 3rd step to be a little less complicated than comparing row by row each update.

Is it possible, and this is a stretch I think...
Have the client receive the dataset, and then use a table adapter and bind the dataset to the form and when the client clicks the "save" or whatever button, just extract the SQL methods from the table adapter for the insert, update, delete and transmit the SQL commands over the wire, and have the server perform them?

Also, the communication is encrypted, so I'm assuming sending data like that would be okay to do.

Any suggestions?

Recommended Answers

All 2 Replies

Instead of sending back the whole dataset, maybe send back a class that contains the changes made.

Eg.

[Serializable]
public class ClientRequestDBChange
{
    public enum ChangeType
    {
        AddRecord,
        EditRecord,
        DeleteRecord
    }
    public ChangeType _ChangeType {get; private set;}
    public string[] _data {get; private set;}
    public string _table {get; private set;}
    public ClientRequestDBChange(ChangeType argChangeType, string[] argChangeData, string argTable)
    {
        _table = argTable
        _data = argChangeData
        _ChangeType = argChangeType
    }
}

In the _data you can either have the raw sql to execute, or a safer (less hack prone) approach would be to just have the data for SQL queries that are predifined on the server (your select, insert, update statements). For example, for editing a table each string in the array would have the new values for the table. You can parse it however you want, really.

The only reason I recommend this is because passing around entire datasets over a network can take up a whole lot of bandwidth when all the server really cares about is what has changed.

Also, imagine 2 clients are connected to the server. 1 Client downloads the data, then another client downloads the data. Client 2 finishes editing faster and sends back his data. Client 1 then sends back his data. Should client 1 overwrite all of client 2's changes? Maybe if there's a really good reason for it.....I cant think of a situation though!

skatamatic,

Excellent idea and thoughts!

Actually, the data being served up would only be accessible by two people at once. Myself, sitting at the server, and my clients. The neat thing is, the data that I would edit is data they cannot edit, but can only view, and the data they can edit is data I could edit, but the whole point of the software is so that I don't have to. The only time that would/should happen is if they send an email to me or call on the phone and say "hey, change my contact phone number" and then at the same time they open the client up and update it themselves.

I do see your point though and I really do like your idea! I never thought about that. It's flexible so it could work for any table and any update type...thanks a ton! I never looked at it that way before! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.