+ Reply to Thread
Results 1 to 8 of 8

Thread: Choose the right start?

  1. #1
    thek is offline VB.NET Forum Newbie thek is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    May 2009
    Posts
    22
    Reputation
    18

    Default Choose the right start?

    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.

    Thanks for any help and hints

  2. #2
    MattP is offline VB.NET Forum All-Mighty MattP has a reputation beyond repute MattP has a reputation beyond repute MattP has a reputation beyond repute MattP has a reputation beyond repute MattP has a reputation beyond repute MattP has a reputation beyond repute MattP has a reputation beyond repute MattP has a reputation beyond repute MattP has a reputation beyond repute MattP has a reputation beyond repute MattP has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2008
    Location
    USA
    Posts
    1,039
    Reputation
    534

    Default

    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 by MattP; 07-09-2009 at 5:10 PM.

  3. #3
    thek is offline VB.NET Forum Newbie thek is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    May 2009
    Posts
    22
    Reputation
    18

    Default

    Quote Originally Posted by MattP View Post
    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 !

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Age
    37
    Posts
    11,043
    Reputation
    1563

    Default

    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.

  5. #5
    thek is offline VB.NET Forum Newbie thek is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    May 2009
    Posts
    22
    Reputation
    18

    Default

    I guess you mean the BindingNavigator?
    Yes.

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

    Code:
    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.

  6. #6
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Age
    37
    Posts
    11,043
    Reputation
    1563

    Default

    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)

  7. #7
    cjard's Avatar
    cjard is offline VB.NET Forum All-Mighty cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Apr 2006
    Age
    66
    Posts
    6,752
    Reputation
    937

    Default

    Quote Originally Posted by thek View Post
    Yes.

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

    Code:
    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:

    Code:
    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

  8. #8
    cjard's Avatar
    cjard is offline VB.NET Forum All-Mighty cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute cjard has a reputation beyond repute
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Apr 2006
    Age
    66
    Posts
    6,752
    Reputation
    937

    Default

    Quote Originally Posted by thek View Post
    • 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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts