Point 1 is not quite correct. You don't create variables. You declare variables and create objects. Code:
'Declare the variable.
Dim table As DataTable
'Create the object and assign it to the variable.
table = New DataTable
That can be condensed to this: Code:
'Declare the variable, create the object and assign it to the variable.
Dim table As DataTable = New DataTable
or even more so to this: Code:
'Declare the variable, create the object and assign it to the variable.
Dim table As New DataTable
Point 2 can be done either using a DataReader or a DataAdapter. Use a DataReader if you don;t need to save changes back to the database but, if you do, use a DataAdapter.
It looks like you've got point 3 covered.
Point 4 involves using the aforementioned DataAdapter. You call Fill to populate a DataTable and Update to save the changes back to the database. Check this out for examples of this an other common ADO.NET scenarios:
Retrieving and Saving Data in Databases
Now, the DataAdapter in that example uses a "last in wins" approach. As you suggest, that could lead to one user overwriting the changes that were saved by another. To avoid that, ADO.NET uses "optimistic concurrency". I'm not going to go into details but, basically, it involves comparing the current data in the database to the original data you retrieved and only saving if they are the same. If they are different, your app must handle the resulting error and proceed appropriately. What's appropriate will vary from app to app. For more, search MSDN and the web for information about optimistic concurrency and how it is implemented in ADO.NET. Note that CommandBuilders use optimistic concurrency by default.
Bookmarks