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. -
sSQL="SELECT * FROM [database].[dbo].[table1],[database].[dbo].[table2] where GF3_EKKO_EBELN like '%" & purchaseorder & "' and DE_Employee = '" & employee & "'"
-
-
<%
-
If (Recordset.Fields("GF3_EKKO_EBELN") not like purchaseorder Then
-
Response.Write "<td align=""left""><span class=""style8"">YOUR RESPONSE IS INVALID</span></td>"
-
Else
-
Response.Write "<INPUT TYPE=""hidden"" id=""purchaseorder"" NAME=""purchaseorder"" class=""inputtext"" VALUE="& purchaseorder &">"
-
Response.Write "<td align=""left""><span class=""style8"">"& purchaseorder &" </span>"
-
Response.Write "<span class=""style8"">Company - " & recordset("GF3_LFA1_NAME1")& "</span></td>"
-
%>
-
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: - sql = "select * from someTable where field1 = 1 and field2 = 2 and field3 = 3"
-
recordset = run sql
-
if recordset count = 0 then
-
print "field1 = 1 and field2 = 2 and field3 = 3 causes no records"
-
-
sql = "select * from someTable where field1 = 1"
-
recordset2 = run sql
-
if recordset2 count = 0 then
-
print "field1 = 1 does not exist"
-
end if
-
-
sql = "select * from someTable where field2 = 2"
-
recordset2 = run sql
-
if recordset2 count = 0 then
-
print "field2 = 2 does not exist"
-
end if
-
-
sql = "select * from someTable where field3 = 3"
-
recordset2 = run sql
-
if recordset2 count = 0 then
-
print "field3 = 3 does not exist"
-
end if
-
-
sql = "select * from someTable where field1 = 1 and field2 = 2"
-
recordset2 = run sql
-
if recordset2 count = 0 then
-
print "field1 = 1 and field2 = 2 does not exist"
-
end if
-
-
sql = "select * from someTable where field1 = 1 and field3 = 3"
-
recordset2 = run sql
-
if recordset2 count = 0 then
-
print "field1 = 1 and field3 = 3 does not exist"
-
end if
-
-
sql = "select * from someTable where field3 = 3 and field2 = 2"
-
recordset2 = run sql
-
if recordset2 count = 0 then
-
print "field3 = 3 and field2 = 2 does not exist"
-
end if
-
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
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. -
-
<%
-
If InStr(Recordset.Fields("GF3_EKKO_EBELN"), purchaseorder)<0 Then
-
Response.Write "<td align=""left""><span class=""style8"">YOUR RESPONSE IS INVALID</span></td>"
-
Else
-
Response.Write "<INPUT TYPE=""hidden"" id=""purchaseorder"" NAME=""purchaseorder"" class=""inputtext"" VALUE="& purchaseorder &">"
-
Response.Write "<td align=""left""><span class=""style8"">"& purchaseorder &" </span>"
-
Response.Write "<span class=""style8"">Company - " & recordset("GF3_LFA1_NAME1")& "</span></td>"
-
%>
-
-
@rfiscus
Use the RecordCount property to see how many records were returned. If it's 0, then you didn't get a match.
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. -
-
<%
-
If InStr(Recordset.Fields("GF3_EKKO_EBELN"), purchaseorder)>0 Then
-
Response.Write "<INPUT TYPE=""hidden"" id=""purchaseorder"" NAME=""purchaseorder"" class=""inputtext"" VALUE="& purchaseorder &">"
-
Response.Write "<td align=""left""><span class=""style8"">"& purchaseorder &" </span>"
-
Response.Write "<span class=""style8"">Company - " & recordset("GF3_LFA1_NAME1")& "</span></td>"
-
Else
-
Response.Write "<INPUT TYPE=""hidden"" id=""purchaseorder"" NAME=""purchaseorder"" class=""inputtext"" VALUE="""">"
-
Response.Write "<td align=""left""><span class=""style8"">YOUR RESPONSE IS INVALID</span>"
-
Response.Write "<span class=""style8"">Company - </span></td>"
-
End If
-
%>
-
-
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? -
sSQL="SELECT * FROM [database].[dbo].[table1],[database].[dbo].[table2] where GF3_EKKO_EBELN like '%" & purchaseorder & "' and DE_Employee = '" & employee & "'"
-
@rfiscus
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: - if record count = 0 then
-
show message saying no record
-
else
-
show record
-
end if
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: - if rs.eof then
-
'No records returned
-
Else
-
'You have at least one good hit
-
End if
Jared
Would I add that before or inside the: -
-
Do while Not recordset.eof
-
-
By necessity it has to be before. If there are no records, the loop isn't going to run.
@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: -
-
sSQL="If (SELECT * FROM [Database].[dbo].[TABLE1],[Database].[dbo].[TABLE2] where GF3_PO_to_NUMBER = '" & purchaseorder & "' and DE_Employee = '" & employee & "') else DE_Employee = '" & employee & "'"
-
-
'create an ADO connection and recordset object
-
Set connection = Server.CreateObject("ADODB.connection")
-
Set recordset = Server.CreateObject("ADODB.Recordset")
-
-
'define the connection string, specify database
-
'driver and the location of database
-
sConnString = "Provider=SQLOLEDB; Data Source = server; Initial Catalog = Database; User Id=username;Password=password;"
-
-
'Open the connection to the database
-
Connection.Open sConnString
-
-
'Open the recordset object, executing the SQL
-
Recordset.Open sSQL, Connection
-
-
if recordset.eof then
-
Response.Write "No records returned"
-
Else
-
Response.Write "You have at least one good hit"
-
End if
-
-
'Looping through the records until the end of the records
-
Do while Not recordset.eof
-
%>
-
<form id="form1" name="form1" method="post" action="add_safety.asp">
-
-
<table border="0" class="formset">
-
-
<tr>
-
<td><span class="style8">Employee #:</span></td>
-
-
<%
-
If employee = "" or (IsNull(employee)) Then
-
Response.Write "<INPUT TYPE=""hidden"" id=""employee"" NAME=""employee"" class=""inputtext"" VALUE="""">"
-
Else
-
Response.Write "<INPUT TYPE=""hidden"" id=""employee"" NAME=""employee"" class=""inputtext"" VALUE="& employee &">"
-
End If
-
Response.Write "<td align=""left""><span class=""style8"">"& employee &" </span>"
-
Response.Write "<span class=""style8""> " & recordset("DE_Name_Formatted(Last,_First)") & "</span></td>"
-
%>
-
</tr>
-
-
<tr>
-
<td><span class="style8">Purchase Order #:</span></td>
-
<%
-
If Recordset.Fields("GF3_PO_to_NUMBER").value = "invalid" Then
-
Response.Write "<INPUT TYPE=""hidden"" id=""purchaseorder"" NAME=""purchaseorder"" class=""inputtext"" VALUE="""">"
-
Response.Write "<td align=""left""><span class=""error"">INVALID! </span>"
-
Response.Write "<span class=""style8"">Company - </span></td>"
-
Else
-
Response.Write "<INPUT TYPE=""hidden"" id=""purchaseorder"" NAME=""purchaseorder"" class=""inputtext"" VALUE="& purchaseorder &">"
-
Response.Write "<td align=""left""><span class=""style8"">"& purchaseorder &" </span>"
-
Response.Write "<span class=""style8"">Company - " & recordset("GF3_LFA1_NAME1")& "</span></td>"
-
End If
-
%>
-
-
......
-
-
Why did you change your SQL? No one said to change it.
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.
If you need to know which one is missing, you need to run two separate queries and check each.
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.
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.
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? -
-
if recordset.eof then
-
Response.Write "<Table>"
-
Response.Write "<tr><td><span class=""style8"">No records returned, please correct the purchase order #.</span><br><br></td></tr>"
-
Response.Write "<tr><td><span class=""style8"">Please press the back button and correct. </span>"
-
Response.Write "<INPUT TYPE=""button"" VALUE=""Back"" onClick=""history.go(-1);return true;"" class=""form_button_clear""></td></tr>"
-
Response.Write "</Table>"
-
End if
-
-
if recordset.eof then
-
Response.Write "<Table>"
-
Response.Write "<tr><td><span class=""style8"">No records returned, please correct your employee number.</span><br><br></td></tr>"
-
Response.Write "<tr><td><span class=""style8"">Please press the back button and correct. </span>"
-
Response.Write "<INPUT TYPE=""button"" VALUE=""Back"" onClick=""history.go(-1);return true;"" class=""form_button_clear""></td></tr>"
-
Response.Write "</Table>"
-
End if
-
-
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: - sql = "select * from someTable where field1 = 1 and field2 = 2 and field3 = 3"
-
recordset = run sql
-
if recordset count = 0 then
-
print "field1 = 1 and field2 = 2 and field3 = 3 causes no records"
-
-
sql = "select * from someTable where field1 = 1"
-
recordset2 = run sql
-
if recordset2 count = 0 then
-
print "field1 = 1 does not exist"
-
end if
-
-
sql = "select * from someTable where field2 = 2"
-
recordset2 = run sql
-
if recordset2 count = 0 then
-
print "field2 = 2 does not exist"
-
end if
-
-
sql = "select * from someTable where field3 = 3"
-
recordset2 = run sql
-
if recordset2 count = 0 then
-
print "field3 = 3 does not exist"
-
end if
-
-
sql = "select * from someTable where field1 = 1 and field2 = 2"
-
recordset2 = run sql
-
if recordset2 count = 0 then
-
print "field1 = 1 and field2 = 2 does not exist"
-
end if
-
-
sql = "select * from someTable where field1 = 1 and field3 = 3"
-
recordset2 = run sql
-
if recordset2 count = 0 then
-
print "field1 = 1 and field3 = 3 does not exist"
-
end if
-
-
sql = "select * from someTable where field3 = 3 and field2 = 2"
-
recordset2 = run sql
-
if recordset2 count = 0 then
-
print "field3 = 3 and field2 = 2 does not exist"
-
end if
-
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.
That explains it very clearly, thank you!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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,...
|
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...
| |