Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / March 2004

Tip: Looking for answers? Try searching our database.

Paging, update, concurrency violation..

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Maurice - 24 Mar 2004 09:36 GMT
Dear reader

because of a large number of records in a database table I'm using paging. 1 record is being fetch everytime I requery the database (just the record the user requires). When I skip to the next record I check if the row has changes. If it does I generate this updatecommand

cmd = New OleDbCommand("UPDATE Customers SET Customers.[Name] = ?, Customers.[Lastname] = ? " &
                                         "WHERE Customers.[CustID] = ?", mdbConnection
cmd.Parameters.Clear(
cmd.Parameters.Add("CustID", OleDbType.Char).Value = CType(dsCustomers.Tables(0).Rows(0).Item("CustID"),Integer)
cmd.Parameters.Add("Name", OleDbType.Char).Value = Me.txtTName.Tex
cmd.Parameters.Add("Lastname", OleDbType.Char).Value = Me.txtTLastname.Tex
daCustomer.UpdateCommand = cm

The problem is now that when I update, I get a concurrency violation (???). The strange thing is I'm the only one using this database and I don't get the concurrency violation when I'm using this parameter

cmd.Parameters.Add("CustID", OleDbType.Char).Value = 2

What could this be

Thx!
Cor - 24 Mar 2004 10:08 GMT
Hi Maurice,

Why do you not put a line between it to debug (I do not know if you use
VS.net)

> cmd.Parameters.Clear()

dim mytest as integer =
CType(dsCustomers.Tables(0).Rows(0).Item("CustID"),Integer))

(and if you have not vs.net)
messagebox.show(mytest.tostring)

> cmd.Parameters.Add("CustID", OleDbType.Char).Value = >
cmd.Parameters.Add("Name", OleDbType.Char).Value = Me.txtTName.Text

I think than you should know it.

I hope this helps?

Cor
Maurice - 24 Mar 2004 11:01 GMT
Hi Cor

The messagebox shows 0
Why do I get a concurrency violation? I don't get it
I constructed the dataset and dataadapter in run-time.
Cor - 24 Mar 2004 11:08 GMT
Hi Maurice,

Show some code from the Select part.
It means that that ID is empty, so there it cannot find the row to update.
(Or you should have a record with an id 0, which you have already readed
(fill) again)

Cor
Maurice - 24 Mar 2004 11:36 GMT
Hi Cor,

the select statement has 4 different selects, depends on what direction the user wants to go to (paging up or down or first or last record):

This is one statement:
selCmd.CommandText = "SELECT TOP " & pageSize & " Customers.[CustID],* FROM Customers " & _
                                       "WHERE Customers.[CustID] > ? ORDER BY Customers.[CustID]"
selCmd.Parameters.Add("CustID", OleDbType.Integer).Value = CType(lastVisibleCustomer, Integer)

I checked the code but the key isn't 0. It has a value. When I enter this value in the code it does update without a concurrency violation. When I refer to the key in the dataset (which has the same value) I do get the concurrency violation.

thx..
Cor - 24 Mar 2004 11:59 GMT
Hi Maurice,

Can you check your columnnames
To check that
messagebox.show(dsCustomers.tables(0).datacolumn(0).name)
messagebox.show(dsCustomers.tables(0).datacolumn(1).name)
etc

Cor
Maurice - 24 Mar 2004 12:01 GMT
Cor this is the situation

(1
cmd = New OleDbCommand("UPDATE Customers SET Customers.[Name] = ?, customers.Lastname]  " &
                                         "WHERE Customers.[CustID] = " & intCurrentKey & "", mdbConnection
cmd.Parameters.Clear(
....

(2
cmd = New OleDbCommand("UPDATE Customers SET Customers.[Name] = ?, customers.Lastname]  " &
                                         "WHERE Customers.[CustID] = ?", mdbConnection
cmd.Parameters.Clear(
cmd.Parameters.Add("CustID", OleDbType.Integer).Value = intCurrentKe
...

Situation 1 works fine, Situation 2 gives a concurrency violation........
Cor - 24 Mar 2004 13:56 GMT
Hi Maurice,

I never used this with OleDb, however the documentation says that it has to
be the same as with the SQL parameter. (Although strange is that that 20 did
work)
> cmd.Parameters.Clear()
> cmd.Parameters.Add("@CustID", OleDbType.Integer).Value = intCurrentKey
> ....

Can you try that?

Cor
Maurice - 24 Mar 2004 15:36 GMT
Hi Cor

when I use the @ I get a lot of errors.
e.g. This doesn't work for typ DBNull

Strange problem, but I will use the first solution which does work. Thank you for the support!!
Ron Allen - 24 Mar 2004 21:16 GMT
#2) You need a second parameter fir the name added BEFORE the CustId
parameter.  OleDb parameters must be added in order.

Ron Allen
> Cor this is the situation:
>
[quoted text clipped - 12 lines]
>
> Situation 1 works fine, Situation 2 gives a concurrency violation.........

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.