Using text input to search Access number column - sql

I have a simple search page with this text input form
<form name="assetInput" action="assetResult.jsp" method="get">
<input type="text" name="assetNo" />
<input type="submit" value="Submit" />
</form>
which takes you to a results page that will search an Access database by the Asset Number you type in the search page. The column's data type is number.
This is the code to get the input from the text box, and my attempt to convert the String to an int.
<%
String assetNumber = request.getParameter("assetNo");
int assetNum = Integer.parseInt(assetNumber);
%>
My query:
rs = stmt.executeQuery( "SELECT * FROM [Inventory Tracking] WHERE (([Inventory Tracking].AssetNumber) = '"+assetNum+"')");
I'm able to search columns from the database whose data type is text, but I keep getting errors when trying to search a number column with a String.
Thanks in advance!

Numbers do not take a delimiter, only text fields.
rs = stmt.executeQuery( "SELECT * FROM [Inventory Tracking] WHERE [Inventory Tracking].AssetNumber = "+assetNum);
You could avoid a lot of problems with a parameter.

Related

Angular 8 update text field in response to another field change

The image above represents a project I'm working on. Of the 3 fields, only purchase price data is manually entered. I use the following markup and TS code to set the Outstanding mortgage field to a percentage of the previously provided figure:
<input type="number" class="form-control" min='0' id="purchaseValueInput" formControlName="purchase_value" (ngModelChange)='setPercentages()'>
...
setPercentages() {
this.mortgage = this.analysisForm.value.market.purchase_value * 0.75;
}
My challenge is I need to do a similar thing for the mortgage payments field but as a percentage of the outstanding mortgage value. Because that value is not manually provided the ngModelChange strategy is not working.
How can I resolve that last step?
Update
In my setPercentages() function, I have attempted to set a variable for mortgage payments but I get the following error:
The specified value "NaN" cannot be parsed, or is out of range.
I suspect it's because the field is regarded as empty even though visually it has data in it. I used the following code:
setPercentages() {
this.mortgage = this.analysisForm.value.market.purchase_value * 0.75;
this.mortgagePayments = (this.analysisForm.value.market.outstanding_mortgage * 0.03) / 12;
}
<input type="number" class="form-control" min='0' id="mortgagePaymentValueInput" formControlName="mortgage_payments" [value]="mortgagePayments">
You could try to bind the mortgage payments to a member variable and in the setPercentages function of the other input, you also update the model via that variable.
If ngModelChange doesn't work for some reason you can try to set the value attribute of that input:
<input type="text" value="$300"></input>
I was assigning my percentage values to variables and interpolation to assign the variable as the value of my input field. That proved to the the wrong approach.
What does work is using form patchValue as shown below:
this.analysisForm.patchValue({
market: {
outstanding_mortgage: this.analysisForm.value.market.purchase_value * 0.75,
}
});

How to get website to accept the amount updated on a field

I am trying to submit a form after updated all the fields but the amount field keep changing back to zero no matter what amount updated. Below is the element of that particular field:
input id="$PAcqCaseCreation$pTransactionAmount" onchange="onAmountChange(this,
document.getElementById('TranNOD').value ,
document.getElementById('TranDecimalSymbol').value,
document.getElementById('TranDecimalSymbolForLocale').value,
document.getElementById('TranThousandsSep').value , 'false' ); "
class="rightJustifyStyle" type="text" size="10"
value="" data-changed="false"
My code:
doc.getElementsByTagName("iframe")(0).contentDocument.getElementsById( _
"$PAcqCaseCreation$pTransactionAmount").innerText = fileLink9

ColdFusion form not submitting data to database

I'm having some trouble with my ColdFusion code,
I have a simple form, and all I want it to do is to add the values to the database. I keep getting the error:
"error code 206
[Macromedia][SQLServer JDBC Driver][SQLServer]Operand type clash: int is incompatible with text"
Here's my code:
<div class="form">
<form method="post" name="color">
ID:
<input type="text" name="id" id="id">
Color Name:
<input type="text" name="color" id="color">
Hex Value:
<input type="text" name="hex" id="hex">
<input type="submit" value="Submit">
</form>
</div>
<div>
<cfif structKeyExists(form, "color")>
<cfquery datasource="bentest" name="insertColor">
USE [benTest]
INSERT INTO color_codes
(id ,color, hexvalue)
VALUES
(#form.id#, '#form.color#', #form.hex#)
</cfquery>
<p>You've added a color to the database!</p>
</cfif>
</div>
And if I remove the single quotes from #form.color#, I get "Invalid column name '(what I entered)'."
If the hexvalue field in the database is a text field, e.g. nvarchar, varchar, text, then at a minimum you will need quotes around the variable... i.e.
<cfquery datasource="bentest" name="insertColor">
USE [benTest]
INSERT INTO color_codes (id ,color, hexvalue)
VALUES (#form.id#, '#form.color#', '#form.hex#')
</cfquery>
However I strongly suggest you also cfqueryparam them too, i.e.
<cfquery datasource="bentest" name="insertColor">
USE [benTest]
insert into
[color_codes] (
[Id],
[Color],
[HexValue]
)
values (
<cfqueryparam value="#Form.Id#" cfquerytype="cf_sql_integer">,
<cfqueryparam value="#Form.Color#" cfquerytype="cf_sql_varchar">,
<cfqueryparam value="#Form.Hex#" cfquerytype="cf_sql_varchar">
)
</cfquery>
You need to add quotes for #form.hex# because it is a string value, not integer:
INSERT INTO color_codes
(id ,color, hexvalue)
VALUES
(#form.id#, '#form.color#', '#form.hex#')
Actually, it looks like your id is a text field as well. Is this how it is set up in the database? You're not doing any verification that the value is numeric.... Often the ID is an auto-incrementing field, and not supplied by the user at all on insert.

How do you update the last row in a table using SQL in ASP

I decided to rephrase my question to make it a bit easier.
I have a form with three fields
<form class="contact_form" action="divProgramProcess.asp" method="post" name="contact_form">
Couch: <input type="text" name="Couch_Current" id="Couch_Current" />
<br/>
Available:
<input type="text" name="Available_Current" id="Available_Current" />
<br/>
Shipment:
<input type="text" name="Shipment_Current" id="Shipment_Current" />
<input type="submit" value="submit" ></form>
The form calls the following code divProgramProcess.asp (shown below)
<%
divrec = request.QueryString("div")
Set rstest = Server.CreateObject("ADODB.Recordset")
rstest.locktype = adLockOptimistic sql = "SELECT top 1 * FROM CensusFacility_Records WHERE division_program = 'Division 1' and jmsday ='Sun' order by JMSUpdateDateTime desc "
rstest.Open sql, db
%>
<%
Shipment_Current = request.form("Shipment_Current")
Couch_Current = request.form("Couch_Current")
Available_Current = request.form("Available_Current")
rstest.fields("Shipment") = Shipment_Current
rstest.fields("Couch") = Couch_Current
rstest.fields("Available") = Available_Current
rstest.update
Response.Redirect("chooseScreen.asp")
%>
Now keep in mind that the column 'JMSUpdateDateTime" is a date field and there are multiple records of 'Division 1" under the division_program column name.
I'm trying to update the last row in my SQL table but everytime I run this script I only update the first record with "Division 1" not the last record. To put it simply: There are 10 records that contain Division 1. All of them have date timestamp columns. How can I update the last record?
Instead of updating via recordset, run an actual UPDATE Statement. Basicaly you will need 2 steps:
Run your SELECT TOP 1 ... query, but retreive just a primary key/identity field from the table (not " * ") and save it into some temp variable
Run actual SQL "UPDATE CensusFacility_Records SET Shipment = ... WHERE TABLE_ID = " & yourTempVariable
(Best would be to create a parametrized query instead of adding parameters to query string inline). This way you're guaranteed to really update specific record.
Try this:
SELECT * FROM CensusFacility_Records WHERE division_program = 'Division 1'
and jmsday ='Sun' and JMSUpdateDateTime = (SELECT MAX(JMSUpdateDateTime)
FROM CensusFacility_Records WHERE division_program = 'Division 1' and jmsday ='Sun')"

Selecting items IN a row

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.