Question Choose the right start?

thek

Member
Joined
May 31, 2009
Messages
22
Programming Experience
Beginner
Hi guys

I learned a lot in this tread

I have to realize that I (hate to say it) must start over.

So what I’m going to make, is a program that can:

  • Hold the data needed
  • Have more than one person to work in the program and updating the data (It’s not a requirement that it’s the same data/records they update (but it would be nice), but at least I’ll make a functionality that locks the data that one person is editing, so that there are no overwrite of data.
  • The database MUST be on a share network

So… I really need some advice on which kind of database I need to create/use, to make sure that the 3 above items is “do-able”.

Earlier I created it (manually) without using the wizards in visual studio, but I ended up with being way over my head. I used an Access database to do this. But – as mentioned earlier – I couldn’t make it happen. :confused:

Thanks for any help and hints
 
I'd recommend reading the DW2 link that cjard posted.

If you're a visual learner this series will be of assistance: Forms over Data Video Series

Here's an article on handling concurrency issues in .NET. The article is for an ASP.NET application but it does go over some of the drawbacks of pessimistic locking and provides a couple of sample stored procedures that you could build from: 15 Seconds : Handling Concurrency Issues in .NET
 
Last edited:
I'd recommend reading the DW2 link that cjard posted.

Read it many times, and I can do it blindfold now ;-)
But I'm unfamiliar with, how to cahnge the navagtion bar? Can I somehow see the code behind the bar?

If you're a visual learner this series will be of assistance: Forms over Data Video Series
Excellent. Thanks !

Here's an article on handling concurrency issues in .NET. The article is for an ASP.NET application but it does go over some of the drawbacks of pessimistic locking and provides a couple of sample stored procedures that you could build from: 15 Seconds : Handling Concurrency Issues in .NET


Thanks again !
 
But I'm unfamiliar with, how to cahnge the navagtion bar? Can I somehow see the code behind the bar?
I guess you mean the BindingNavigator? It is just bound to a BindingSource. The buttons are assigned the regular action to do, for example in MoveNextItem the default BindingNavigatorMoveNextItem button is selected. When this button is clicked the BindingSource.MoveNext method is called. If you need custom code you can doubleclick the button and write code for it's Click event, to prevent the default call to BS method you just select "(none)" for its MoveNextItem in this case.
 
I guess you mean the BindingNavigator?

Yes.

But there is no code behind the BindingNavigatorMoveNextItem_Click, it looks like this:

VB.NET:
Private Sub BindingNavigatorMoveNextItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveNextItem.Click

    End Sub

Where can I see the code that move one record forward? (When I create database access via the wizard)

If I can see the code, then I can get rid of the navigationsbar that the wizard created, and make my own button, with the code from "BindingNavigatorMoveNextItem_Click" in it.
 
As I said, the navigator is connected to a BindingSource (BindingSource property), then various buttons on the navigator is assigned particular actions (like the move next), when these buttons are clicked the corresponding action method on the BS is called. There is no client code necessary to do this in a default configuration. Have a look at the members of BindingSource class and you'll see it's obvious how they all map to the various navigator actions, you can also see this map in help for BindingNavigator Class (System.Windows.Forms)
 
Yes.

But there is no code behind the BindingNavigatorMoveNextItem_Click, it looks like this:

VB.NET:
Private Sub BindingNavigatorMoveNextItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveNextItem.Click

    End Sub

Where can I see the code that move one record forward? (When I create database access via the wizard)


To say John's post another way:

You can't see it, because Microsoft wrote the BindingNavigator. It takes in a BindingSource as a parameter, and then simply calls bindingSource.MoveNext every time you click on what it knows to be the Next button (you tell it that too)

Simply put, their code might look like this:

VB.NET:
Class BindingNavigator
  
  Private _bs as BindingSource
  Property BindSource as BindingSource
    Set
      _bs = value
    End Set
  End Property

  Private _mni as Button
  Property MoveNextItem as Button
    Set
      _mni = value
      AddHandler(_mni.Click, AddressOf(MNIClickHandler))
    End Set
  End Property

  Private Sub MNIClickHandler
    _bs.MoveNext()
  End Sub
End Class

If you really wanna see the code then use Reflector to decompile the .NET framework, but it will be like this in essence:
When the MoveNextItem is set to a button, the click handler of that button is assigned INSIDE the bindingnavigator code to a handler that is ALSO inside the bindingnavigator code
Every time you click the button, it just calls MoveNext on the bindingsource the bindingnavigator is attached to (ALSO inside the bindingnavigator code)

If you want to "roll your own" MoveNext handler you HAVE to tell the BindingNavigator it has no set MoveNextItem
-> Open the properties for the BindingNavigator
Find the MoveNextItem setting
Set it to NONE

Now you can roll your own click handler in your own code
 
  • Hold the data needed
  • Have more than one person to work in the program and updating the data (It’s not a requirement that it’s the same data/records they update (but it would be nice), but at least I’ll make a functionality that locks the data that one person is editing, so that there are no overwrite of data.
  • The database MUST be on a share network
Use SQL Server Express

Note for item 2, you can use pessimistic locking but it is sometimes dumb. By default doing code like DW" link in my sig shows you, creates OPTIMISTIC locking, which is "hope that noone else changed the record, but throw an exception if someone did"

If 2 people d/l a record and then one changes and saves
and then the other changes and saves, he gets an exception because the query is written so that old values in the client are compared with the db values. If 0 rows are affected, it means someone changed a value

So when you get your exception you have to handle it:
Overwrite user1's changes with user2's
Keep user1's
Show user 2 both sets of changes and let them choose which of each
Merge the changes, letting user1's changes win if there is a conflict
Merge the changes, letting user2's changes win if there is a conflict

You must write this code. it is not automatic
 

Latest posts

Back
Top