I have the following code;
Dim rdr As SqlCeDataReader = cm_sel.ExecuteReader
If rdr.HasRows Then
While rdr.Read
Documents.DeleteDocument(rdr.Item("fID"))
End While
End If
The error I get is:
SQL Server Compact does not support calls to HasRows property if the
underlying cursor is not scrollable.
So how am I supposed to check if data exists before actually reading the DataReader?
EDIT
the whole code:
Dim con As New SqlCeConnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ToString)
Dim cm_sel As New SqlCeCommand("SELECT fID FROM Files WHERE fCatID=" & catID, con)
Try
con.Open()
Dim rdr As SqlCeDataReader = cm_sel.ExecuteReader
If rdr.HasRows() Then
While rdr.Read
Documents.DeleteDocument(rdr.Item("fID"))
End While
End If
Return "{'result':'ok'}"
Catch ex As Exception
Return "{'result':'error'}"
Finally
con.Close()
con.Dispose()
End Try
You could call directly
reader.Readsince will return false if there are no rows. Simply remove theifstatement surrounding thewhile.UPDATED CODE: