sqlCEReader problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dim myReader as SqlCeReade

if(myReader.Read)The
control=Tru
els
control=Fals
EndI
When I try to read some data with the above code from SQLCE database I get an sqlce exception. if myReader is null(nothing returned from the query) this problem occurs
My aim is to control whether any record returned from table or not
If I replace the code with the following then there is no problem
while(myReader.Read
control=Tru
endWhil
I wonder why this happens?
 
ibad said:
Dim myReader as SqlCeReader

if(myReader.Read)Then
control=True
else
control=False
EndIf
When I try to read some data with the above code from SQLCE database I get
an sqlce exception.
if myReader is null(nothing returned from the query) this problem occurs .
My aim is to control whether any record returned from table or not.
If I replace the code with the following then there is no problem:
while(myReader.Read)
control=True
endWhile
I wonder why this happens??

You'll have to post some more code before we can tell, really.
 
Private Function MyFunction(ByVal y As Long) As Boolea

Dim strSQL As Strin
Dim rdr As SqlCeDataReade
Dim cmd As SqlCeCommand = connection.CreateCommand 'connection is defined previousl

MyFunction = Fals

strSQL = " SELECT Z FROM TBLXXX WHERE Y=y "

cmd.CommandText = strSQ
rdr= cmd.ExecuteReade

If (rdr.Read) The
MyFunction = Tru
End I
cmd.Dispose(
rdr.Close(
rdr.Dispose(

End Function
 
ibad said:
Private Function MyFunction(ByVal y As Long) As Boolean

Dim strSQL As String
Dim rdr As SqlCeDataReader
Dim cmd As SqlCeCommand = connection.CreateCommand 'connection is defined previously

MyFunction = False

strSQL = " SELECT Z FROM TBLXXX WHERE Y=y "

cmd.CommandText = strSQL
rdr= cmd.ExecuteReader

If (rdr.Read) Then
MyFunction = True
End If
cmd.Dispose()
rdr.Close()
rdr.Dispose()

End Function

And where exactly is the exception thrown?
 
If (rdr.Read) Then

This line is where the exception is thrown..
But if I change this line with while loop then the problem is solved.I think we can not write rdr.Read into ifThenElse statement but I don't know the reason.
 
ibad said:
If (rdr.Read) Then

This line is where the exception is thrown..
But if I change this line with while loop then the problem is
solved.I think we can not write rdr.Read into ifThenElse statement
but I don't know the reason.

You definitely should be able to.

What is the exception, exactly? What's the error message within it?
 
ibad said:
sqlCE Exception

No, that's the *type* of the exception. Please give us the *details* of
it. Drill down in the debugger and examine the Errors property, the
Message property (of SqlCeException, not just Exception) etc.

There's far more detail in most exceptions than just "something went
wrong".
 
Back
Top