Adagio
Well-known member
- Joined
- Dec 12, 2005
- Messages
- 162
- Programming Experience
- Beginner
I often get this error when running several select sql statements in a loop
The code looks something like this
It does seem to favor some IDs, but not always. And there's nothing special about them in the database as far as I can tell
Does anyone have any idea on what's going on here?
The code looks something like this
VB.NET:
Private Shared connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\Adrian\Q-rapport\Database\kvalData_test.mdb"
Private Shared command As OleDbCommand
public shared function doSomething() as list (of someClass)
dim lst as list (of someClass) = new list (of someClass)
for i as integer = 0 to 100
dim some as new someClass
Dim dataReader As OleDbDataReader = runSelectSql("SELECT something FROM someTable WHERE ID = " & i)
datareader.read()
some.someVar = datareader.item("something")
datareader.close
command.connection.close()
lst.add(some)
next
return lst
end sub
private shared function runSelectSql(strSql as string) as OleDbDataReader
Dim dataReader As OleDbDataReader
Try
command = New OleDbCommand()
With command
.Connection = New OleDb.OleDbConnection(connectionString)
.Connection.Open()
.CommandText = strSql
dataReader = .ExecuteReader(CommandBehavior.Default)
End With
Catch oexpData As OleDb.OleDbException
command.Connection.Close()
return nothing
end try
Return dataReader
end function
It does seem to favor some IDs, but not always. And there's nothing special about them in the database as far as I can tell
Does anyone have any idea on what's going on here?