473,386 Members | 1,647 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,386 software developers and data experts.

ASP/SQL Empty Recordset producing blank page.

14
In essence, I have a asp form page that posts itself to another asp page for validation, as long as the second page finds an equal PO number in the sql query, everything works great, if there is not a result in the SQL table the page is blank, I have been trying to say if PO is in recorset then response write the field else write response invalid or something similar. I have obviously written the code wrong, any help would be appreciated. As I said if the resultant set is good, it all works.

Expand|Select|Wrap|Line Numbers
  1. sSQL="SELECT * FROM [database].[dbo].[table1],[database].[dbo].[table2] where GF3_EKKO_EBELN like '%" & purchaseorder & "' and DE_Employee = '" & employee & "'"
  2.  
  3. <%   
  4. If (Recordset.Fields("GF3_EKKO_EBELN") not like purchaseorder Then
  5. Response.Write "<td align=""left""><span class=""style8"">YOUR RESPONSE IS INVALID</span></td>"
  6. Else
  7. Response.Write "<INPUT TYPE=""hidden"" id=""purchaseorder"" NAME=""purchaseorder"" class=""inputtext"" VALUE="& purchaseorder &">"
  8. Response.Write "<td align=""left""><span class=""style8"">"& purchaseorder &" &nbsp;</span>"
  9. Response.Write "<span class=""style8"">Company - " & recordset("GF3_LFA1_NAME1")& "</span></td>"
  10. %>
  11.  
Apr 23 '12 #1

✓ answered by Rabbit

Just to be clear, the .eof does not check to see if there are no records returned. It only checks to see if the cursor is at the end of the record set. It's just a happenstance that if there are no records, then it will be at the end of the record set.

You don't have to write the result twice, that makes no sense. You just have to do the check twice, once for one field, and then again for the other field. Each time with a different query.

There's no way to know which WHERE clause "causes no records" from a single query. You must first establish that there are no matching records, then check each and every combination of WHERE clauses to find out which combination of clauses cause no records.

For example:
Expand|Select|Wrap|Line Numbers
  1. sql = "select * from someTable where field1 = 1 and field2 = 2 and field3 = 3"
  2. recordset = run sql
  3. if recordset count = 0 then
  4.    print "field1 = 1 and field2 = 2 and field3 = 3 causes no records"
  5.  
  6.    sql = "select * from someTable where field1 = 1"
  7.    recordset2 = run sql
  8.    if recordset2 count = 0 then
  9.       print "field1 = 1 does not exist"
  10.    end if
  11.  
  12.    sql = "select * from someTable where field2 = 2"
  13.    recordset2 = run sql
  14.    if recordset2 count = 0 then
  15.       print "field2 = 2 does not exist"
  16.    end if
  17.  
  18.    sql = "select * from someTable where field3 = 3"
  19.    recordset2 = run sql
  20.    if recordset2 count = 0 then
  21.       print "field3 = 3 does not exist"
  22.    end if
  23.  
  24.    sql = "select * from someTable where field1 = 1 and field2 = 2"
  25.    recordset2 = run sql
  26.    if recordset2 count = 0 then
  27.       print "field1 = 1 and field2 = 2 does not exist"
  28.    end if
  29.  
  30.    sql = "select * from someTable where field1 = 1 and field3 = 3"
  31.    recordset2 = run sql
  32.    if recordset2 count = 0 then
  33.       print "field1 = 1 and field3 = 3 does not exist"
  34.    end if
  35.  
  36.    sql = "select * from someTable where field3 = 3 and field2 = 2"
  37.    recordset2 = run sql
  38.    if recordset2 count = 0 then
  39.       print "field3 = 3 and field2 = 2 does not exist"
  40.    end if
  41. end if
In this example, the original 3 clauses have 6 possible combinations, not counting the original.

In your question, you have 2 clauses, so you have 2 possible combinations not counting the original.

17 3235
rfiscus
14
I have also tried this but same thing, if the record is valid, it will show the correct data, if the form field is not like a row from the sql table the page comes up blank.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%   
  3. If InStr(Recordset.Fields("GF3_EKKO_EBELN"), purchaseorder)<0 Then
  4. Response.Write "<td align=""left""><span class=""style8"">YOUR RESPONSE IS INVALID</span></td>"
  5. Else
  6. Response.Write "<INPUT TYPE=""hidden"" id=""purchaseorder"" NAME=""purchaseorder"" class=""inputtext"" VALUE="& purchaseorder &">"
  7. Response.Write "<td align=""left""><span class=""style8"">"& purchaseorder &" &nbsp;</span>"
  8. Response.Write "<span class=""style8"">Company - " & recordset("GF3_LFA1_NAME1")& "</span></td>"
  9. %>
  10.  
  11.  
@rfiscus
Apr 23 '12 #2
Rabbit
12,516 Expert Mod 8TB
Use the RecordCount property to see how many records were returned. If it's 0, then you didn't get a match.
Apr 23 '12 #3
rfiscus
14
I know that I am getting a record count of 0 when I type in a wrong purchaseorder number, that is the issue, I am trying to make sure that it does not display the blank recordset, I want it to display a generic error in its place. I tried this but same results, displays if valid but blank page if invalid.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%   
  3. If InStr(Recordset.Fields("GF3_EKKO_EBELN"), purchaseorder)>0 Then
  4. Response.Write "<INPUT TYPE=""hidden"" id=""purchaseorder"" NAME=""purchaseorder"" class=""inputtext"" VALUE="& purchaseorder &">"
  5. Response.Write "<td align=""left""><span class=""style8"">"& purchaseorder &" &nbsp;</span>"
  6. Response.Write "<span class=""style8"">Company - " & recordset("GF3_LFA1_NAME1")& "</span></td>"
  7. Else
  8. Response.Write "<INPUT TYPE=""hidden"" id=""purchaseorder"" NAME=""purchaseorder"" class=""inputtext"" VALUE="""">"
  9. Response.Write "<td align=""left""><span class=""style8"">YOUR RESPONSE IS INVALID</span>"
  10. Response.Write "<span class=""style8"">Company - </span></td>"
  11. End If
  12. %>
  13.  
  14.  
Apr 23 '12 #4
rfiscus
14
I believe the real problem is that since the query is not pulling up a good record then it stops processing the page. Is there a way to say if the result set in the sql query produces a good result then process rest of page, if not go to a different page?

Expand|Select|Wrap|Line Numbers
  1. sSQL="SELECT * FROM [database].[dbo].[table1],[database].[dbo].[table2] where GF3_EKKO_EBELN like '%" & purchaseorder & "' and DE_Employee = '" & employee & "'"
  2.  


@rfiscus
Apr 23 '12 #5
Rabbit
12,516 Expert Mod 8TB
You said you know you're getting a record count of 0. So use that. Check the record count in code. That's what I was saying in my post.

In pseudo code, it would be:
Expand|Select|Wrap|Line Numbers
  1. if record count = 0 then
  2.    show message saying no record
  3. else
  4.    show record
  5. end if
Apr 23 '12 #6
jhardman
3,406 Expert 2GB
Rabbit is right. Your query is coming back blank so your if statement is meaningless, it would be better to base it off of record count. I like to use the recordset.eof property for that type of thing. If when you open the recordset you get "end of file" (eof) that means no records were returned:
Expand|Select|Wrap|Line Numbers
  1. if rs.eof then
  2.    'No records returned
  3. Else
  4.    'You have at least one good hit
  5. End if 
Jared
Apr 24 '12 #7
rfiscus
14
Would I add that before or inside the:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Do while Not recordset.eof
  3.  
  4.  
Apr 24 '12 #8
Rabbit
12,516 Expert Mod 8TB
By necessity it has to be before. If there are no records, the loop isn't going to run.
Apr 24 '12 #9
rfiscus
14
@Rabbit
So now it errors out with:
Microsoft OLE DB Provider for SQL Server

error '80040e14'

An expression of non-boolean type specified in a context where a condition is expected, near 'else'.

/data_entry/safety/safety_t.asp, line 63

I have looked this up but this should not be doing an update or insert at this point.


The code is as follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. sSQL="If (SELECT * FROM [Database].[dbo].[TABLE1],[Database].[dbo].[TABLE2] where GF3_PO_to_NUMBER = '" & purchaseorder & "' and DE_Employee = '" & employee & "') else DE_Employee = '" & employee & "'"
  3.  
  4. 'create an ADO connection and recordset object
  5. Set connection = Server.CreateObject("ADODB.connection") 
  6. Set recordset = Server.CreateObject("ADODB.Recordset")
  7.  
  8. 'define the connection string, specify database 
  9. 'driver and the location of database 
  10. sConnString = "Provider=SQLOLEDB; Data Source = server; Initial Catalog = Database; User Id=username;Password=password;" 
  11.  
  12. 'Open the connection to the database
  13. Connection.Open sConnString
  14.  
  15. 'Open the recordset object, executing the SQL
  16. Recordset.Open sSQL, Connection
  17.  
  18. if recordset.eof then
  19.     Response.Write "No records returned"
  20. Else
  21.     Response.Write "You have at least one good hit"
  22. End if 
  23.  
  24. 'Looping through the records until the end of the records
  25. Do while Not recordset.eof
  26. %>
  27. <form id="form1" name="form1" method="post" action="add_safety.asp">
  28.  
  29. <table border="0" class="formset">
  30.  
  31. <tr>
  32.     <td><span class="style8">Employee #:</span></td>
  33.  
  34. <%
  35. If employee = "" or (IsNull(employee)) Then
  36. Response.Write "<INPUT TYPE=""hidden"" id=""employee"" NAME=""employee"" class=""inputtext"" VALUE="""">"
  37. Else
  38. Response.Write "<INPUT TYPE=""hidden"" id=""employee"" NAME=""employee"" class=""inputtext"" VALUE="& employee &">"
  39. End If
  40. Response.Write "<td align=""left""><span class=""style8"">"& employee &" &nbsp;&nbsp;&nbsp;&nbsp;</span>"
  41. Response.Write "<span class=""style8"">&nbsp;&nbsp;" & recordset("DE_Name_Formatted(Last,_First)") & "</span></td>"
  42. %>
  43. </tr>
  44.  
  45. <tr>
  46.     <td><span class="style8">Purchase Order #:</span></td>
  47. <%   
  48. If Recordset.Fields("GF3_PO_to_NUMBER").value = "invalid" Then
  49. Response.Write "<INPUT TYPE=""hidden"" id=""purchaseorder"" NAME=""purchaseorder"" class=""inputtext"" VALUE="""">"
  50. Response.Write "<td align=""left""><span class=""error"">INVALID!&nbsp;&nbsp;</span>"
  51. Response.Write "<span class=""style8"">Company - </span></td>"
  52. Else
  53. Response.Write "<INPUT TYPE=""hidden"" id=""purchaseorder"" NAME=""purchaseorder"" class=""inputtext"" VALUE="& purchaseorder &">"
  54. Response.Write "<td align=""left""><span class=""style8"">"& purchaseorder &" &nbsp;</span>"
  55. Response.Write "<span class=""style8"">Company - " & recordset("GF3_LFA1_NAME1")& "</span></td>"
  56. End If
  57. %>
  58.  
  59. ......
  60.  
  61.  
Apr 24 '12 #10
Rabbit
12,516 Expert Mod 8TB
Why did you change your SQL? No one said to change it.
Apr 24 '12 #11
rfiscus
14
Good question, stupid mistake, I pasted from what I was trying on a test site, sorry. It does look like it works with my original sql statement which makes it much easier.

The only real issue is that if any of the records fails it responds with the Else response, is there a way to make it so you know which field failed? For example, whether or not it was the employee number or the purchaseorder number that is invalid? That is why I was trying to construct the SQL with the if statement.

Thanks for all your time.
Apr 24 '12 #12
Rabbit
12,516 Expert Mod 8TB
If you need to know which one is missing, you need to run two separate queries and check each.
Apr 24 '12 #13
rfiscus
14
Sorry, I am not usually this needy but could you give me an example for one of the separate queries, this is literally the last step and I will be done with this site. Thanks.
Apr 24 '12 #14
Rabbit
12,516 Expert Mod 8TB
Don't really need an example. Do what you're doing now. Except do it twice. Once to check just the PO number. And do the same thing again to check the employee.
Apr 24 '12 #15
rfiscus
14
If I do it twice, it just posts both responses even if just one of the fields is blank. It seems like there would have to be a way to see the difference between the two fields in the select statement, otherwise, doesn't the recordset.eof just check to see if any records exist, not which part of the sql is causing it to produce no records? I thought you were saying to just write the recordset.eof statement twice?

Expand|Select|Wrap|Line Numbers
  1.  
  2. if recordset.eof then
  3.     Response.Write "<Table>"
  4.     Response.Write "<tr><td><span class=""style8"">No records returned, please correct the purchase order #.</span><br><br></td></tr>"
  5.     Response.Write "<tr><td><span class=""style8"">Please press the back button and correct.&nbsp;&nbsp;&nbsp;</span>"
  6.     Response.Write "<INPUT TYPE=""button"" VALUE=""Back"" onClick=""history.go(-1);return true;"" class=""form_button_clear""></td></tr>"
  7.     Response.Write "</Table>"
  8. End if
  9.  
  10. if recordset.eof then
  11.     Response.Write "<Table>"
  12.     Response.Write "<tr><td><span class=""style8"">No records returned, please correct your employee number.</span><br><br></td></tr>"
  13.     Response.Write "<tr><td><span class=""style8"">Please press the back button and correct.&nbsp;&nbsp;&nbsp;</span>"
  14.     Response.Write "<INPUT TYPE=""button"" VALUE=""Back"" onClick=""history.go(-1);return true;"" class=""form_button_clear""></td></tr>"
  15.     Response.Write "</Table>"
  16. End if
  17.  
  18.  
Apr 25 '12 #16
Rabbit
12,516 Expert Mod 8TB
Just to be clear, the .eof does not check to see if there are no records returned. It only checks to see if the cursor is at the end of the record set. It's just a happenstance that if there are no records, then it will be at the end of the record set.

You don't have to write the result twice, that makes no sense. You just have to do the check twice, once for one field, and then again for the other field. Each time with a different query.

There's no way to know which WHERE clause "causes no records" from a single query. You must first establish that there are no matching records, then check each and every combination of WHERE clauses to find out which combination of clauses cause no records.

For example:
Expand|Select|Wrap|Line Numbers
  1. sql = "select * from someTable where field1 = 1 and field2 = 2 and field3 = 3"
  2. recordset = run sql
  3. if recordset count = 0 then
  4.    print "field1 = 1 and field2 = 2 and field3 = 3 causes no records"
  5.  
  6.    sql = "select * from someTable where field1 = 1"
  7.    recordset2 = run sql
  8.    if recordset2 count = 0 then
  9.       print "field1 = 1 does not exist"
  10.    end if
  11.  
  12.    sql = "select * from someTable where field2 = 2"
  13.    recordset2 = run sql
  14.    if recordset2 count = 0 then
  15.       print "field2 = 2 does not exist"
  16.    end if
  17.  
  18.    sql = "select * from someTable where field3 = 3"
  19.    recordset2 = run sql
  20.    if recordset2 count = 0 then
  21.       print "field3 = 3 does not exist"
  22.    end if
  23.  
  24.    sql = "select * from someTable where field1 = 1 and field2 = 2"
  25.    recordset2 = run sql
  26.    if recordset2 count = 0 then
  27.       print "field1 = 1 and field2 = 2 does not exist"
  28.    end if
  29.  
  30.    sql = "select * from someTable where field1 = 1 and field3 = 3"
  31.    recordset2 = run sql
  32.    if recordset2 count = 0 then
  33.       print "field1 = 1 and field3 = 3 does not exist"
  34.    end if
  35.  
  36.    sql = "select * from someTable where field3 = 3 and field2 = 2"
  37.    recordset2 = run sql
  38.    if recordset2 count = 0 then
  39.       print "field3 = 3 and field2 = 2 does not exist"
  40.    end if
  41. end if
In this example, the original 3 clauses have 6 possible combinations, not counting the original.

In your question, you have 2 clauses, so you have 2 possible combinations not counting the original.
Apr 25 '12 #17
rfiscus
14
That explains it very clearly, thank you!
Apr 25 '12 #18

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

Similar topics

6
by: Paul Robinson | last post by:
I am developing a website in ASP that connects to a Sybase database. However, when I try to open a connection to the database the page will not load. The script does not timeout, nor the...
2
by: Ravi | last post by:
I have a webpage(with a text field and a button) which prompts for a local file and attempts to load the file in the window if the user clicks on the button. The javascript code onClick event uses...
2
by: William Bradley | last post by:
The record has 56 fields but the whole record can be fitted on to one page in a report, with room to spare. My problem is that the report is producing a second blank page and I can't seem to...
2
by: David R | last post by:
I've been following the "ASP.NET Custom Error Pages" article (http://www.aspnetresources.com/articles/CustomErrorPages.aspx), but when I implement either subscribing to base.Error or overriding...
0
ADezii
by: ADezii | last post by:
When you create a Recordset, you may want to know immediately whether that Recordset actually contains any Rows. There are Recordsets that don't return any Rows and you may need to take different...
8
code green
by: code green | last post by:
I have been working with a script I have inherited that uses the ADODB class. I want to run a query that checks a record is unique across the primary key and date field in a MsSql DB before...
2
by: hackmagic | last post by:
Hi, i have a form that normally has a Recordset containing only one record bound to it. i have replaced the navigation buttons with my own and the 'New Record' button assigns an empty Recordset...
3
by: paitoon | last post by:
Hi, In my site i set a serach engine page.Which customer could put key word and find the user name in database, I set in one page will show 40 people. If over 40 the page will set to be other...
3
by: Flo100 | last post by:
Hi, I have a recordset which I have populated with a query. I have an empty recordset. I would like to take value of a field in every single record, which is a string. Search if the 4rth...
4
by: ipez75 | last post by:
Hello everyone, I have a web application written in asp 6.0, my problem is that I execute a sql server store procedure and I get an empty recordset, while executing the same sp on query anlyzer I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.