Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

objDataReader true\false

  Asked By: Lewis    Date: Jan 06    Category: Asp.net    Views: 1124
  

this is my function:


Dim sqlH = "SELECT " & fldHeader & " FROM " & tableName & " WHERE (id = " & id & ")"

Dim objCommand = New SqlCommand(sqlH, myConnection)

'Get a datareader

Dim objDataReader As SqlDataReader

objDataReader = objCommand.ExecuteReader()

if obj DataReader.read() = false then

return "no record"

end if

While objDataReader.Read()

resForTitle = objDataReader("mHeader")

End While

objDataReader.Close()

Return resForTitle



even if there is record the function is returning empty string.

if im deleteing the :

if obj DataReader.read() = false then

return "no record"

end if

it's working well...

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Muriel Dunn     Answered On: Jan 06

.read is essentially a .movenext + a check for EOF combined into one.

IF obj DataReader.read()

positions you on record  #1 if there is 1.


While objDataReader.Read()

resForTitle = objDataReader("mHeader")

End While

the read  at TOP OF LOOP positions you on record #2.

Thus it needs to rewritten as:

DO
resForTitle = objDataReader("mHeader")

LOOP while objdataReader.read()

 
Answer #2    Answered By: Trae Thompson     Answered On: Jan 06

my query ALWAYS return  1 row.
i tried:


If objDataReader.Read Then

While objDataReader.Read()

resForTitle = objDataReader("mHeader")

End While

Else

Return "no records"

End If

what i missed?

 
Didn't find what you were looking for? Find more on objDataReader true\false Or get search suggestion and latest updates.




Tagged: