Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

4 unrelated questions about VB.net

Status
Not open for further replies.

sillysod

Technical User
Jan 6, 2004
300
GB
Hi Guys,

I have two questions

With datasets i understand you take a copy of the data to work with and then write the changes from dataset to database

So how does record locking work? IE if 3 people have three copies of the data then how are the changes written ?

and what about newrecords ? is there a common and reliable way of ensuring a sequential sequence of invoice numbers and the like.



My other question is about properties of forms

I have a text box, when user types in the text box my app "catches" the tilde key being pressed.

What i want to happen is open another form that has just a listview control on it.

i have this working no problems. when the tilde keypress is caught i use a function to build a SQL string based on a partial search string in the text box and loads this into the listview.

The problem i have is passing the value selected form list back to the original text box.

What i want is for the form i open to function like a msgbox or a inputbox, in that the function is "paused" until user makes a selection

So what im trying to create is a glorified inputbox()

Im sure this must be possible since VB is very versatile in this sort of area.



Last but not least, is there a way to stop more than one instance of a particular form being opened? Currently i have a boolean value which i update in the open and close events. and then check against this before opening another copy. Is this the easiest way?


Thanks in advance



 
1) Check the CurrencyManager object, I think it might do some of what you are looking for. if not, We have an application here that uses a locking method that makes entries into a database table that all of the clients refer to. Before any updates/inserts/deletes are made, checks to the lock table are made to ensure consistency.



2) A chunk of code that I've posted a few times now:
On the form that you want to operate like a dialog
Code:
Public Function GetSelection() As String
 Me.ShowDialog()
 Return Me.List1.SelectedValue
End Function

On the calling form:
Code:
dim frm2 as Form2
SomeStringVariable = frm2.GetSelection

change Form2 to the name of your selection form.



3) Yes, but I can't remember the code off the top of my head and it's past quiting time ;)

-Rick

----------------------
 
I thought about using a "records locked" table. however, i know you can stop a user exiting database, so code can be run etc to remove the particular record locks.
What happens if a user crashes out of the database? you would get records which were locked indefinately
wouldnt you have to get everybody off the system and then clear the table manually

You answer to question 2 is EXACTLY what i was looking for, i have been messing about with allsorts to try and get this working. defining properties and passing the names of forms and controls around through several functions etc etc

thanks alot for the help
 
for #1, having an administration utility that can remove locks is pretty much a requirement if you use a lock table. Also, lots of testing, crashing is not something that should happen in any program, specificly not one that will have enough users and data to require data locking.

-Rick

----------------------
 
I've always had trouble understanding how a multi-user lock
works with a dataset. Thankfully, I have never had to set one up.

Could you explain in a little more detail how the locking application you use works?


Dazed and confused
 
The locking app we have here I don't do too much work on. Since I've come on board I've been swamped in standardizing our development and working on a new reporting system. Not much need for locks on a reporting system ;)

I'm not privy to all the exact details of the system here (The thing is immense, and what I do know of it would take way too long to type out)

There are different ways of handling locking though, and I beleive some level of functionality is built into ADO.Net. Since ADO.Net is by default a disconnected dataset, it has to ensure data integrity from the time the records are retreived until the point where they are saved. Of course, this only helps if you are doing all of your work through a dataset. If you are working with a more distributed data system, a manual system will have to be implimented. That means that you must track when a user retreives a piece of data, and then check when saving that peice if anyone else is viewing it, if it has been updated since you pulled it, or any other processes. There are numerous different types of locks, and many different ways to approach them. I'm guessing someone has writen a book on it too ;)

-Rick

----------------------
 
Yuop been looking for a book. Might pop into the shops on Saturday and have another scout around.
In the mean time, this is quite a good article in MSDN.
Surprised I've never found it before ( I think they must have slipped it in recently ).

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconoptimisticconcurrency.htm

Or search for 'Optimistic Concurrency'.




Dazed and confused
 
Sillysod:
If you can find it, I highly recommend the book "Database Programming With Visual Basic .Net" from apress. Tons of info, including an appendix on locking. Plus lots of other very interesting info.
 
thanks alot for all the info, and i will definately pick that book up from amazon.

With referencing to crashing, EVERY app crashes at some point, whether it be the computers fault or the app.

there are times when users will ctrl + alt + del out of the app

Having said that i guess it would be possible to stick to one instance of the app and have it clear any locked records in the table upon entry to the system

Then the simple rule is, if you crash out, log back in as soon as you can to clear any locked records.

 
What you need to do is trap errors in your application and allow the user to gracefully exit your app(s). Simply pressing ctrl + Alt + del can lead to serious data corruption, which you probably want to avoid. Your apps need to flush any data or roll back transactions, etc to a previous know state before the app quits.

You also need to take a look at WHY your users pc's are crashing. Then look at possible remedies (i.e. how fragmented are the hard drives, do you have network issues, etc.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top