Click here to Skip to main content
15,899,679 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: textbox validation Pin
Paul Conrad22-Dec-07 13:06
professionalPaul Conrad22-Dec-07 13:06 
QuestionHow to connect to a ODBC database in c# or visual basic? Pin
mcirosoftmohan20-Dec-07 9:37
mcirosoftmohan20-Dec-07 9:37 
GeneralRe: How to connect to a ODBC database in c# or visual basic? Pin
Christian Graus20-Dec-07 9:48
protectorChristian Graus20-Dec-07 9:48 
GeneralRe: How to connect to a ODBC database in c# or visual basic? Pin
mcirosoftmohan20-Dec-07 10:06
mcirosoftmohan20-Dec-07 10:06 
GeneralRe: How to connect to a ODBC database in c# or visual basic? Pin
Christian Graus20-Dec-07 11:03
protectorChristian Graus20-Dec-07 11:03 
GeneralRe: How to connect to a ODBC database in c# or visual basic? Pin
GuyThiebaut21-Dec-07 6:05
professionalGuyThiebaut21-Dec-07 6:05 
QuestionConcurrency exceptions with only one user? Pin
craigmg7820-Dec-07 5:10
craigmg7820-Dec-07 5:10 
GeneralRe: Concurrency exceptions with only one user? [modified] Pin
Dave Kreskowiak20-Dec-07 7:36
mveDave Kreskowiak20-Dec-07 7:36 
craigmg78 wrote:
As I had previously understood it - obviously incorrectly - concurrency errors were caused by two users trying to change the same row of data at the same time.)


That's true - you got that wrong. A concurrency failure occurs when an application goes to update a row in a database and the data in that row has changed since the application read the row OR the application made a mistake in identifying the row to be updated. For instance, when your application gets a row from the database, it sees something like:
ID  FirstName  LastName   PhoneNumber
 1   Joe        Schmoe      555-1212

Say you are trying to change the phone number. You make the change in the application and the app is trying to write the new data back to database. Well, id order to identify the record, the code is using an SQL query that looks something like this:
UPDATE ContactsTable
SET FirstName = 'Joe', LastName = 'Schmoe', PhoneNumber = '123-4567'
WHERE ID = 1 AND FirstName = 'Joe' AND LastName = 'Schmoe' AND PhoneNumber = '555-1212'

Notice that the WHERE clause in the SQL statement mentions all the fields in the table and gives the values of the fields as they are supposed to be now, when the application read this record. This is how the code matches up the record it intends to update with the record in the table. If any of these fields do not match, the record is not found, and hence cannot be updated. The "number of rows affected" by this SQL statement should return 1 if the change is successfully written.

If the "number of rows affected" comes back 0, or greater than 1, this throws the concurrency exception in your code. Now, what are the possible causes of "rows affected" returning a non-1 value?

1) The record in the database has been changed by an outside source. This is either another user updated the same record, the database changed the record in response to some other application, or some problem with the database.

2) The data in the WHERE clause of the SQL UPDATE statement is not correct. What the application read before is not what the app is now submitting in the WHERE clause to uniquely identify this record.

For example, your application read the record in the example above (1, Joe, Schmoe, 555-1212), but, for some reason, when it build the SQL statement to update the record with new data, the data it used in the WHERE clause doesn't match what it read. It might be doing something like:
UPDATE ContactsTable
SET FirstName = 'Joe', LastName = 'Schmoe', PhoneNumber = '123-4567'
WHERE ID = 4 AND FirstName = 'Frank' AND LastName = 'Schmoe' AND PhoneNumber = '555-1212'

Notice the ID and FirstName fields in the WHERE clause no longer match what was originally read. This too can cause a concurrency violation, without another user using the database.


A guide to posting questions on CodeProject[^]



Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007




modified on Thursday, December 20, 2007 2:01:13 PM

GeneralRe: Concurrency exceptions with only one user? Pin
craigmg7820-Dec-07 8:10
craigmg7820-Dec-07 8:10 
Generalvalidation help Pin
hassanasp20-Dec-07 1:28
hassanasp20-Dec-07 1:28 
AnswerRe: validation help Pin
Ujjaval Modi20-Dec-07 1:39
Ujjaval Modi20-Dec-07 1:39 
GeneralRe: validation help Pin
hassanasp20-Dec-07 13:06
hassanasp20-Dec-07 13:06 
GeneralRe: validation help Pin
Christian Graus20-Dec-07 14:23
protectorChristian Graus20-Dec-07 14:23 
GeneralRe: validation help Pin
Paul Conrad22-Dec-07 13:07
professionalPaul Conrad22-Dec-07 13:07 
GeneralConnecting two computers using VB.NET Pin
Benny_Lava19-Dec-07 23:58
Benny_Lava19-Dec-07 23:58 
GeneralRe: Connecting two computers using VB.NET Pin
Dave Kreskowiak20-Dec-07 7:42
mveDave Kreskowiak20-Dec-07 7:42 
QuestionHow to Control Concurency using Threads in vb.net Pin
Vimalsoft(Pty) Ltd19-Dec-07 23:17
professionalVimalsoft(Pty) Ltd19-Dec-07 23:17 
AnswerRe: How to Control Concurency using Threads in vb.net Pin
Dave Kreskowiak20-Dec-07 7:56
mveDave Kreskowiak20-Dec-07 7:56 
QuestionBitmap&Bitmap Pin
The real $M@19-Dec-07 22:22
The real $M@19-Dec-07 22:22 
GeneralRe: Bitmap&Bitmap Pin
Christian Graus19-Dec-07 23:26
protectorChristian Graus19-Dec-07 23:26 
GeneralRe: Bitmap&Bitmap Pin
The real $M@20-Dec-07 23:36
The real $M@20-Dec-07 23:36 
GeneralRe: Bitmap&Bitmap Pin
MikeMarq20-Dec-07 11:24
MikeMarq20-Dec-07 11:24 
GeneralRe: Bitmap&Bitmap Pin
The real $M@20-Dec-07 23:35
The real $M@20-Dec-07 23:35 
GeneralRe: Bitmap&Bitmap Pin
MikeMarq21-Dec-07 8:44
MikeMarq21-Dec-07 8:44 
AnswerRe: Bitmap&Bitmap Pin
The real $M@22-Dec-07 1:54
The real $M@22-Dec-07 1:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.