-
May 16th, 2013, 10:44 AM
#1
Thread Starter
Hyperactive Member
Concurrency violation
I have the following very simple code and it baffles me why I'm getting a concurrency violation on this. I use this type of thing all the time and the only difference i see in this example is I am setting the values in columns "alternate1" and "alternate2" etc. before I update. These are all valid column names.
I am not including the code on the function _getalts because it returns data correctly each time. I already tried moving the update command and accept changes to the very end after it loops through the datarows, but I get the same concurrency error.
I would appreciate any help on this.
HTML Code:
OleDbDataAdapter1.Fill(DataSet11, "siegerhotels")
Dim hod As String
Dim recnum As Integer = 0
Dim altnum As Integer = 0
Dim date1 As Date
Dim lat As Double
Dim lon As Double
Dim dr As DataRow
For Each dr In DataSet11.Tables("siegerhotels").Rows
recnum = recnum + 1
hod = dr("HPROP_NO")
lat = dr("lat")
lon = dr("lon")
date1 = dr("hoteldate")
Dim dv As New DataView()
dv = _getAlts(hod, lat, lon, date1)
If dv.Count > 0 Then
Dim n As Integer
For n = 0 To dv.Table.Rows.Count - 1
If n = 5 Then Exit For
dr("ALTERNATE" & n + 1.ToString) = dv(n)("PROPNAME")
dr("ALTRATE" & n + 1.ToString) = dv(n)("USEPRICE")
dr("HOD" & n + 1.ToString) = dv(n)("SABRE_HOD")
Next n
End If
OleDbDataAdapter1.Update(DataSet11)
DataSet11.AcceptChanges()
Next dr
-
May 16th, 2013, 11:24 AM
#2
Re: Concurrency violation
vb.net Code:
hod = dr("HPROP_NO") lat = dr("lat") lon = dr("lon") date1 = dr("hoteldate")
The first thing I see is you are not properly accessing the items within the DataRow. It should look like this:
vb.net Code:
hod = dr.Item("HPROP_NO").ToString() lat = CDbl(dr.Item("lat")) lon = CDbl(dr.Item("lon")) date1 = CDate(dr.Item("hoteldate"))
You should also reverse the order of your update and commit changes commands:
This:
OleDbDataAdapter1.Update(DataSet11)
DataSet11.AcceptChanges()
Should be:
DataSet11.AcceptChanges()
OleDbDataAdapter1.Update(DataSet11)
-
May 16th, 2013, 12:25 PM
#3
Re: Concurrency violation
I don't see any open or close commands for the database so it seems safe to assume that ..
OleDbDataAdapter1.Fill(DataSet11, "siegerhotels")
....
OleDbDataAdapter1.Update(DataSet11)
... is the source of your concurrency violation. You should never have the database open for any longer than necessary in any case.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 16th, 2013, 01:02 PM
#4
Thread Starter
Hyperactive Member
Re: Concurrency violation
I've never used open or close with the update method. I've never had problems with it either. I use it about 100 times throughout code I have been writing for 8 years. I do use the open and close connection when it tells me I need to. Like in execute non-query or some function like that.
Anyway, here is my new code: It doesn't give me an error anymore, but it also doesn't update my table. I inserted the messagebox to make sure the values I was putting in were valid and they are. I also tried just adding straight text into one of the fields like "test" and it still didn't update the table. I checked the adapter and connection and it's pointing to the right table.
HTML Code:
OleDbDataAdapter1.Fill(DataSet11, "siegerhotels")
Dim hod As String
Dim recnum As Integer = 0
Dim altnum As Integer = 0
Dim date1 As Date
Dim lat As Double
Dim lon As Double
Dim dr As DataRow
For Each dr In DataSet11.Tables("siegerhotels").Rows
recnum = recnum + 1
'hod = dr("HPROP_NO")
'lat = dr("lat")
'lon = dr("lon")
'date1 = dr("hoteldate")
hod = dr.Item("HPROP_NO").ToString()
lat = CDbl(dr.Item("lat"))
lon = CDbl(dr.Item("lon"))
date1 = CDate(dr.Item("hoteldate"))
Dim dv As New DataView()
dv = _getAlts(hod, lat, lon, date1)
If dv.Count > 0 Then
Dim n As Integer
For n = 0 To dv.Table.Rows.Count - 1
If n = 5 Then Exit For
MessageBox.Show(dv(n)("PROPNAME") & vbLf & dv(n)("USEPRICE") & vbLf & dv(n)("SABRE_HOD"), "test", MessageBoxButtons.OK)
dr("ALTERNTE" & n + 1.ToString) = dv(n)("PROPNAME")
dr("ALTRATE" & n + 1.ToString) = dv(n)("USEPRICE")
dr("HOD" & n + 1.ToString) = dv(n)("SABRE_HOD")
Next n
End If
Next dr
DataSet11.AcceptChanges()
OleDbDataAdapter1.Update(DataSet11)
-
May 16th, 2013, 01:42 PM
#5
Re: Concurrency violation
I use it about 100 times throughout code I have been writing for 8 years.
I'm not sure how getting away with doing it wrong 100 or even a 1000 times is meant to justify continuing doing it wrong (an argument which is all too prevalent around these parts)!
But moving on. Where is the command for ...
OleDbDataAdapter1.Update(DataSet11)?
You don't seem to have a command builder or an SQL command so how does it know what to do?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|