473,325 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

need some guidance for Record Not Found

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.Clos eConnection)

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---
Nov 18 '05 #1
3 2197
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

"luna" <lu**@themoon.com> wrote in message
news:Gb************@newsfep1-gui.server.ntli.net...
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.Clos eConnection)

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---

Nov 18 '05 #2
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

"Michael Ramey" <raterus@localhost> wrote in message
news:OM**************@TK2MSFTNGP10.phx.gbl...
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

"luna" <lu**@themoon.com> wrote in message
news:Gb************@newsfep1-gui.server.ntli.net...
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.Clos eConnection)

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---


Nov 18 '05 #3
nm sussed it ! - thanks for the pointer tho!!
"luna" <lu**@themoon.com> wrote in message
news:dL****************@newsfep2-gui.server.ntli.net...
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

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: new_GUY | last post by:
I have a HUGE project (at least for me) and need some guidance. I am trying to create a database for a local university movie club that allows users to input there basic personal information...
0
by: Shawn Carter | last post by:
Hi, I'm taking my first and only SQL course (just trying to get my degree as I prefer network administration and loathe any type of programming per se) and I have the following problem. If I...
3
by: Shawn Carter | last post by:
Hi, I'm taking my first and only SQL course (just trying to get my degree as I prefer network administration and loathe any type of programming per se) and I have the following problem. If I...
3
by: Liz Malcolm | last post by:
Hello and TIA for guidance. I am building a reusable search procedure (thanks go to Graham Thorpe for his example that set me on my way). Everything works up until the 2nd match is found, the...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
3
by: Rajesh Sharma | last post by:
Dear all, I have a table with the names and address of all my dealers along with their telephone nos. I want to create a form, wherein I just enter the telephone no; the query/function searches...
5
by: Jon Bowlas | last post by:
Hi listers, I wrote this script in Zope some time ago and it worked for a while, but now I'm getting the following error: TypeError: coercing to Unicode: need string or buffer, NoneType found ...
14
by: optimum | last post by:
hi i am kind of new to programming, i have managed to create a simple payroll database in C++, but now i am trying to convert in into C but i am keep getting error, can anyone help me convert this...
7
by: yaragallamurali | last post by:
Hi I have thought about my earlier post, refined it and reposting it. I am actually new to schema designing. I have read few articles about data modeling and started building schemas for real time...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.