I've got a DB connection to my SQL Server on Azure. Two columns are showing on the page but not showing the other 2. Columns are company name and further details
Company Name is standard business name
Further Details stores URLs to more information
I've tried the SQL statement in SQL Management and it displays data what should be shown.
I've checked the parameters of the column, they're both nvarchar(Max) it shows as -1 when clicking to modify the size of the column. Does this mean it has unlimited size?
The file type is Classic ASP with inline CSS and HTML inside.
Below is what is being called in the database.
<%
Session.LCID=2057
Dim connpiudb, rspiudata, strSQL, fldThis, strSQL2, strSQL3, strcategory
strcategory = Request.querystring("category")
Set connpiudb = Server.CreateObject("ADODB.Connection")
Set rspiudata = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT companyname, courtnumber, cronumber, furtherdetails FROM piudata WHERE category LIKE '" & strCategory & "%' Order by companyname"
strValue = Request.QueryString(<%= rspiudata.Fields("companyname") %>)
response.write strSQL
response.write strValue
<!-- strSQL = "SELECT companyname , courtnumber , cronumber, furtherdetails FROM piudata WHERE category LIKE '%c%' Order by companyname" -->
connpiudb.Open strConnect
rspiudata.open strSQL, connpiudb
%>
Below is how the database is stored in the HTML table.
<!--content start-->
<FONT FACE="Arial" size="2">
<TABLE BORDER="0" cellpadding="2" width="60%"><TR>
<%
Do Until rspiudata.EOF
%>
<TR><TD width="40%"><B>Company Name:</B></TD><TD width="60%"><%= rspiudata.Fields("companyname") %></TD></TR>
<TR><TD width="40%"><B>Further Details:</B></TD><TD width="60%"><%=rspiudata.Fields("furtherdetails") %></TD></TR>
<TR><TD width="40%"><B>Court Number:</B></TD><TD width="60%"><%= rspiudata.Fields("courtnumber") %></TD></TR>
<TR><TD width="40%"><B>Company Registered Number:</B></TD><TD width="60%"><%= rspiudata.Fields("cronumber") %></TD></TR>
<TR><TD width="100%" colspan="2"><HR></TD></TR>
<%
rspiudata.movenext
Loop
rspiudata.Close
Set rspiudata = Nothing
connpiudb.close
%>
</TABLE>
I am struggling to understand what the actual issue is. Only thing I've thought of is that the columns sizes default to -1 when setting it as MAX or that Classic ASP does not support NVARCHAR(max)
Any help will be great.
Before going further on this, following code needs to be corrected
<%
...
strValue = Request.QueryString(<%= rspiudata.Fields("companyname") %>)
I understood you have it for debug purposes however it has neither valid syntax (you inject <% %> within existing server code block nor valid operator (Request.QueryString is for query strings) nor right place (recordset is defined but not opened).
And read about sql injections.
Related
I am able to display the ItemID perfectly fine and the ItemIDs group together. When I try the SQL statement in MS Access the quantities add up perfectly fine but I can't manage to replicate this in HTML.
This is the code
<%
dim Con,rs, sql
set con = server.CreateObject("ADODB.Connection")
set rs = server.CreateObject("ADODB.Recordset")
Con.Open("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=" & Server.MapPath("Database/Name.accdb"))
sql = "SELECT ItemID, SUM(Quantity) FROM tblCreatedItems GROUP BY ItemID ORDER BY tblCreatedItems.ItemID"
rs.open sql, Con
%>
<body>
<table width="467" align="center">
<th colspan="5"><strong>Items Sold</strong></th>
<tr>
<td width="119"><strong>ItemID</strong></td>
<td width="165"><strong>Quantity</strong></td>
</tr>
<tr>
<% while not rs.eof%>
<td><%=rs("ItemID")%></td>
<td>
<% dim sql2
set sql2=con.execute("SELECT SUM(Quantity) FROM tblCreatedItems GROUP BY ItemID ORDER BY tblCreatedItems.ItemID" )
response.Write(sql2)
%></td>
</tr>
<% rs.movenext
wend
%>
</table>
</body>
You are already grouping by the itemid in the first query, and don't need a second query to show the sum.
In your sql add an alias (a name to reference the field) to the SUM field:
change SUM(Quantity) to SUM(Quantity) as NoOfItems (or whatever you like, as an alias)
The sql statement becomes:
SELECT ItemID, SUM(Quantity) as NoOfItems
FROM tblCreatedItems
GROUP BY ItemID
ORDER BY tblCreatedItems.ItemID
And Then:
<td><%=rs("NoOfItems")%></td>
should show your sum field.
So, your table code becomes:
<table width="467" align="center">
<th colspan="5"><strong>Items Sold</strong></th>
<tr>
<td width="119"><strong>ItemID</strong></td>
<td width="165"><strong>Quantity</strong></td>
</tr>
<tr>
<% while not rs.eof%>
<td><%=rs("ItemID")%></td>
<td><%=rs("NoOfItems")%></td>
</tr>
<% rs.movenext
wend
%>
</table>
My requirement is to insert artist details and his picture through jsp into oracle database and retrieve back information and picture through another jsp program.
artist table has five columns, four are varchar2 and fifth column is blob type.
I have successfully inserted but facing problem in retrieving. Because it is only displaying image but no other information. Below is the code.
PreparedStatement ps=con.prepareStatement("select * from artist");
ResultSet rs=ps.executeQuery();
while(rs.next()){ %>
<table><tr><th>artist fast name:</th><td><%=rs.getString(1) %></td></tr>
<tr><th>artist middle name:</th><td><%=rs.getString(2) %></td></tr>
<tr><th>artist last name</th><td><%=rs.getString(3) %></td></tr>
<tr><th>artist job</th><td><%=rs.getString(4) %></td></tr>
<tr><th>artist image</th><td><img src="
<%
Blob bl=rs.getBlob(5);
byte[] image=bl.getBytes(1, (int)bl.length());
response.setContentType("image/jpeg");
OutputStream o = response.getOutputStream();
o.write(image);
o.flush();
o.close();
}
%>" height="100" width="100" alt="bye"/> </td></tr>
</table>
<%
con.close();
please suggest me to display complete info from table
I am currently having a problem with some thumbnail images in a classic ASP website. Essentially, I have a database in Microsoft Access that contains three tables: One with the pictures and their info, another that is linked to the pictures table and contains location information and a third table which just has some text for the website.
On the page which is coded below, each image in the database has its corresponding thumbnail printed onto the page. The user can then click on the thumbnail and be taken to the larger image with some associated information.
My problem is that the thumbnails are repeating themselves, up to 11 times.
<% option explicit %>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Places</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<!-- #include file="conn.asp" -->
<div id="container">
<!-- #include file="nav.asp" -->
<% dim SQL, info
' 0 1 2 3 4
SQL = "select PicturesTable.id, filename, location, title, description"&_
" from PicturesTable, locationsTable"&_
" where PicturesTable.locationNum = locationsTable.id"&_
" order by locationsTable.id"
set info=conn.execute(SQL)
This is my loop where I think the problem is.
if info.eof then
response.write "No data found."
end if
do until info.eof
response.write "<a href=""images.asp?i=" & info(1) & """>" &_
"<img src=""thumbs/" & info(1) & """></a>"
info.movenext
loop
%>
</div>
<%
conn.close
%>
</body>
</html>
So the problem was in fact that I had designed the database poorly in access and I was repeating the records when they should have been unique. Hence, the repeated images. Deleting the repeated records gave me the solution. Thanks for the help anyway.
Try the following SQL instead; the problem is likely that you need to JOIN the two tables.
SQL = "SELECT PicturesTable.id, filename, location, title, description"&_
" FROM PicturesTable"&_
" LEFT JOIN locationsTable"&_
" ON PicturesTable.locationNum = locationsTable.id"&_
" ORDER BY locationsTable.id
I'm fetching records from the SQL Server 2000 database using Classic ASP. This is what the code I have used.
ASP Code:
<form name="search" method="post" onsubmit="return attention();">
<table width="60%" border="0" cellpadding="2" cellspacing="0" style="margin:0 auto">
<tr>
<td colspan="2"><h1 style="color:#003399;">Search for Certificate of Analysis</h1></td>
</tr>
<tr>
<td valign="bottom">Product number <sup style="color:#EE0000;font-size:1.3em">*</sup></td>
<td valign="bottom">Lot number</td>
</tr>
<tr>
<td width="30%" valign="top">
<input type="text" name="input1" size="20"/>
</td>
<td valign="top">
<input type="text" size="20" name="input2"/>
<input style="background-color:#ffffff;border:0px;cursor:pointer" size="10" type="submit" name="sub" value=">>" />
</td>
</tr>
</table>
<%
if request.Form("sub") <> "" then
Dim fname, lname
fname= request.Form("input1")
lname= request.Form("input2")
session("n") = fname & lname
sql = "Select * from search where cat_no_batch_no LIKE '"&request.Form("input1")&"%' OR cat_no_batch_no='"&session("n")&"'"
rs.open sql, con, 1, 2
if rs.eof then
response.write("Please provide a valid Cat No.")
else
do while not rs.eof
%>
<table border="1" cellpadding="5" cellspacing="0" width="60%" style="margin:0 auto; border-collapse:collapse;border-color:#999999">
<tr>
<td width="50%"><%=rs("cat_no_batch_no")%></td>
<td width="10%">Click to open <a target="_blank" href="http://localhost/search1/<%=rs("pdf_path")%>"><%=rs("cat_no_batch_no")%></a></td>
</tr>
</table>
<%
rs.movenext
loop
end if
rs.close
end if
%>
</form>
Above the LIKE statement works as expected and displays multiple records which contains similar Cat No..
Issue rises when I input a Cat No in first Input box and Lot Number in another. My desired output should have been just a single record to display as I have given Cat No. and Lot Number , but it shows multiple records.
I have provided the images to be more clear.
In this image below I have put 6106021 as the product number so it displays two entries.
In this image I have put 6106021 as the product number and 218111 as the Lot Number, it shows two entries instead of 1. This is what the issue, it should show one entry as Lot number are unique while cat number can be the same.
Read your question to yourself and think about what you are saying:
You state "My desired output should have been just a single record to display as I have given Cat No. and Lot Number"
But in your SQL you write where cat_no_batch_no LIKE '"&request.Form("input1")&"%' OR cat_no_batch_no='"&session("n")&"'
The key words are AND vs. OR
In your mind you are thinking both conditions must be true, but your query says otherwise. If you want both conditions to be true then you must use the AND operator.
Naoki is on to something - you are going to have to modify your SQL depending upon which criteria are specified.
I guess you can write two separate SQL queries, according as the "Lot number" is provided or not.
Your code may goes like below:
if lname = "" then
sql = "Select * from search where cat_no_batch_no LIKE '"&request.Form("input1")&"%'"
else
sql = "Select * from search where cat_no_batch_no LIKE '"&session("n")&"%'"
end if
I hope this could help
I'm developing a website for Tenants to find properties. When they sign up, they can choose the property types that they are interested, for example: Apartment or House.
When a Tenant logs into their account, they can then do a search for properties. The search form is prepopulated with the values that they originally entered on sign up, for example: City, Postcode and so on.
The form also needs to display some checkboxes with the relevant boxes ticked for the Property Types that they selected on sign up. I'm having some problems getting this to work and wondered if there is anyone who could correct the code for me?
I believe I need to use an 'IN' statement so that the relevant checkboxes would be ticked, if the IDs for those properties are found in the CustomerReqPropertyType column. The CustomerReqPropertyType column is varchar(50) and as an example, if a user has selected Apartment and House, it is store in the row as 2, 4 (as there is a separate table with the Property Types.
This is the code I have on the page;
<%
While (NOT rspropertytype.EOF)
%>
<li>
<input type="checkbox" name="txtPropertyType" id="txtPropertyType" value="<%=(rspropertytype.Fields.Item("PropertyTypeID").Value)%>"<% If Not rstenantrequirements.EOF Or Not rstenantrequirements.BOF Then %><%If (Not isNull((rstenantrequirements.Fields.Item("CustomerReqPropertyType").Value))) Then If (CStr(rspropertytype.Fields.Item("PropertyTypeID").Value) = CStr((rstenantrequirements.Fields.Item("CustomerReqPropertyType").Value))) Then Response.Write("")%><% End If ' end Not rstenantrequirements.EOF Or NOT rstenantrequirements.BOF %> />
<label for="txtPropertyType"><%=(rspropertytype.Fields.Item("PropertyTypeTitle").Value)%></label>
</li>
<%
rspropertytype.MoveNext()
Wend
If (rspropertytype.CursorType > 0) Then
rspropertytype.MoveFirst
Else
rspropertytype.Requery
End If
%>
I would be very grateful for any help.
In order for a checkbox to be checked the checked property must equal "checked".
e.g.
<input type="checkbox" name="something" value="somethingElse" checked="checked" />
I suspect that in your code the rspropertytype and rstenantrequirements recordsets could be consolidated into one recordset generated from one SQL statement.
e.g.
SELECT pt.*
, CASE
WHEN ISNULL(tr.CustomerReqPropertyType,0) = 0 THEN 0
ELSE 1 END AS [checked]
FROM propertytype AS [pt]
LEFT JOIN tenantrequirements AS [tr]
ON pt.PropertyTypeID = tr.CustomerReqPropertyType
WHERE ...
Then your ASP code could be simplified as well.
e.g.
<%
While (NOT rs.EOF)
Dim pID : pID = rs("PropertyTypeID")
Dim pTitle : pTitle = rs("PropertyTypeTitle")
Dim checked : checked = "" : If (rs("checked") = 1) Then checked = "checked"
%>
<li>
<input type="checkbox" name="txtPropertyType" id="txtPropertyType<%=pID%>" value="<%=pID%>" checked="<%=checked%>" />
<label for="txtPropertyType<%=pID%>"><%=pTitle%></label>
</li>
<%
rs.MoveNext()
Wend
%>
This is really hard to follow. First I'd break up that line to where your while is you can just set a variable and print that to page. I assume you're trying to set the checkbox checked. What I would do is make sure the value returned isn't null assuming this is a query that just returns the property type and you left joined it with the table that has the descriptions in it when they are set for the property in question. I don't see you ever print checked to the checkbox so it's never going to be checked anyway.