473,407 Members | 2,312 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,407 software developers and data experts.

If then statement if record exists

14
So this code works great as long as there is a record otherwise it is just blank, I have tried several if then statements but I can't seem to make it work. How can I if then this statement?:

Expand|Select|Wrap|Line Numbers
  1. <%        
  2.     Set oRs=Server.CreateObject("adodb.recordset")
  3.     strSQL = "SELECT TOP 1 tag, time, round(value, 3) as value FROM pi.piarchive..picomp2 where tag = 'C4_4AQ10P01' and time > DATEADD(DAY, -15, GETDATE()) and value is not null order by time desc"
  4.     oRs.Open strSQL, conn        
  5.  
  6.     Do while not oRs.EOF
  7.     Response.Write "<td align=""center""><input type=""text"" id=""jtd2nox"" value= '" & oRs ("value") & "' name=""jtd2nox"" class=""inputtext1""/></td>"
  8.     oRs.MoveNext 
  9.     loop        
  10.     %>
  11.  
Jul 26 '12 #1

✓ answered by jhardman

The if statement you are looking for is
Expand|Select|Wrap|Line Numbers
  1. if oRs.eof
this returns true if there are no records, or if you have looped through all the records and reached the end. Try putting your if statement right before the do loop.

Jared

6 4386
jhardman
3,406 Expert 2GB
The if statement you are looking for is
Expand|Select|Wrap|Line Numbers
  1. if oRs.eof
this returns true if there are no records, or if you have looped through all the records and reached the end. Try putting your if statement right before the do loop.

Jared
Jul 26 '12 #2
rfiscus
14
This seems to create two input boxes then, first a blank one and then one populated with 'test'. Am I using the if statement incorrectly?

Expand|Select|Wrap|Line Numbers
  1.  
  2. if oRs.eof then
  3.     Response.Write "<td align=""center""><input type=""text"" id=""ows1nox"" value= 'test' name=""ows1nox"" class=""inputtext1""/></td>"
  4.     Else
  5.     Do while not oRs.EOF
  6.     Response.Write "<td align=""center""><input type=""text"" id=""ows1nox"" value= '" & oRs ("value") & "' name=""ows1nox"" class=""inputtext1""/></td>"
  7.     oRs.MoveNext 
  8.     loop
  9.     End If
  10.  
  11.  
Jul 30 '12 #3
rfiscus
14
Disregard, I had an extra line of code from troubleshooting, this worked great, thank you.

@rfiscus
Jul 30 '12 #4
jhardman
3,406 Expert 2GB
Glad you got it working. Let me make two comments on your code.
1- whenever you have a long section of html to write, it might make sense to end the asp code and restart it after you are done like this:
Expand|Select|Wrap|Line Numbers
  1. if oRs.eof then %>
  2. <Td align="center"><input type="text">
  3. <%
  4. End if 
Notice that I don't have to worry about escaping my quote marks. I find this is easier than using "response.write" if the code is longer than just a line.
2- the do loop is already conditional. It will be skipped if there are no records, so you don't need an else clause. Just if - end if.

Jared
Jul 30 '12 #5
rfiscus
14
Cool on not needing the Else clause. If I am writing a lot of HTML I do end my asp code instead of using response.write, sometimes if it is just one line it is easier just to escape it out. Thanks for your input.
Jul 30 '12 #6
Fary4u
273 100+
or u can try different one too. as advance check.
Expand|Select|Wrap|Line Numbers
  1. If not oRs.eof Then
Aug 2 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: ST | last post by:
Hi, I'm sort of in a rush here...I'm sort of new to vb.net and I'm trying to write the syntax to check a sql table to see if the record already exists based on firstname and lastname text fields...
1
by: David C. Barber | last post by:
I'm trying to determine if any matching records exist on a LIKE query performing a partial match of last names to a remote back-end database in the most efficient manner possible. LAN Traffic...
5
by: BerkshireGuy | last post by:
Hello everyone, I have a bond form that a user uses to enter data. One of my fields, is PolicyNumber. I added some code on the Before Update event of txtPolicyNumber that checks to see if...
6
by: Opie | last post by:
What would be a more efficient way for me to determine if a record in an SQL DB table exists? Right now, I have a try/catch like this: try {...
3
by: fuimens | last post by:
Hi, With mysql-4.0.20, I have a problem inserting data with foreign key references, MySQL saying ERROR 1216: Cannot add or update a child row: a foreign key constraint fails The message is...
33
by: Kevin Brammer | last post by:
I'm trying to use seek to check for the existence of a record before saving, so there are no duplicate entries (is there another way?). I have a "groups" table, which has GroupID Island...
6
by: Matt | last post by:
I need some guidance on how to handle an issue. I have an .asp page that correctly queries a table and returns data if a 'job number' and week ending date exist and the user can update the...
6
by: Helena666 | last post by:
Hi Its been a while since I have built a database using access and vba and am a bit rusty. I am using a command button on a form to write a record to a table, using an append query. However I need...
2
by: Gilles Ganault | last post by:
Hello I need to check if a phone number exists in a database. Using the following SQL statement, what is the right way to code this in PHP? $dbh = new PDO("sqlite:test.sqlite"); $sql =...
7
by: djpaul | last post by:
Hello! I want to check if a record exists in the last 30 records that were added. For example, i have a table wich contains about 34000 records by now. But i want to check if the songID is in the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.