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)
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.
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)
Re: Concurrency violation
Quote:
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?