need some guidance for Record Not Found

L

luna

need to display a label if a record is not found - tried a few things but it
appears to be ignoring me!!

code is currently like this - you can also see the test i did - must be
doing something obviously wrong
(its friday..)

cheers mark

Dim sql As String = "Select * from Personal where Personal.ID=" &
userid.Text.ToString
Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
Dim Cmd As New System.Data.SqlClient.SqlCommand(sql, conn)
Dim objDR As System.Data.sqlclient.SqlDataReader
conn.Open()
objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

While objDR.Read()

'If Not objDR.IsDBNull(0) Then
'exist.Text = "No Records Found"
'Else : exist.Text = objDR("ID")
'End If

exist.Text = objDR("ID")
If exist.Text.ToString = "" Then
exist.Text = "No Records Found"
End If

If objDR.IsDBNull(1) Then
surname1.Text = ""
Else : surname1.Text = objDR("surname1")
End If

---rest of code---
 
M

Michael Ramey

Well I don't know exactly what you are doing, but this should help you
determine if a datareader has rows or not. I believe this is just .net 1.1
though

after you set the datareader,

if objDR.HasRows = true then
....
end if

HTH,
--MIchael
 
L

luna

If objDR.HasRows Then
exist.Text = objDR("ID")
Else : exist.Text = "No Records Found"

Didn't seem to do the trick either - basically im searching a database based
on ID - if a record doesn't exist i want a label
to say that "the record doesnt exist"

theres nothing wrong as theres no error messages - but it just doesnt work -
itll display the ID number no problem - but it seems to just ignore the Else
:

cheers

mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top