Apologies about the language, I'm maintaining a legacy system which is all in ASP Classic.
I have a html page which has content generated from my SQL Server via ASP
<form method="POST">
<div class="container">
<table id="table" class="table">
<thead class="thead-dark">
<tr>
<th scope="col" data-field="article">Article</th>
<th scope="col" data-field="item">QTY/th>
I then generated the content with a while loop from my dB which displays the content correctly :
<%
While not grs.eof
%>
<tr>
<!--SQL query from ASP-classic-->
<th><%=grs.fields("Article")%></th>
<input type="number" class="form-control" id="Quant" placeholder="<%=grs.fields("QTY")%>" name="qty"></th>
<%
grs.movenext
wend
%>
</tr>
</table>
</form>
Now, above my table I have a button
<button type="submit" value="Submit" class="btn btn-primary mb-2" name="B1">Confirm</button>
When my end user clicks submit, I want all the values to be updated into my SQL server, now as this is within a for loop I wasn't sure where the Update query would go.. I have this so far
<%
If request.form("B1")="Submit" Then
If QTY = "" Then
QTY = 0
Else
QTY = request.form("QTY")
'Update SQL'
gsSQL2 = "UPDATE dB SET quant ='" & QTY & "' WHERE ID = '" & request.querystring("ID") & "' And Article = '" & grs.fields("Article") &"'"
gobjConn.Execute(gsSQL2)
(please note my code is indented properly in my IDE)
Now, when I click submit within the While loop I get the ID number seperated by a comma, so I know it's updating but I'm really unsure as to what I'm doing wrong..?
any help would be much appreciated.
if any further information is needed let me know.
Expected output is to display some Article Codes codes on a website and take a response from the user, then write that output to my SQL dB where the Article = Article and ID = ID.
main query to generated content (this doesn't match my sample data but I'll post incase the mistake is in the query itself)
gsSQL = "SELECT ID, Article, [Item Name] as name, [Stock Quantity] as qty, Built, Boxed, Actual from dB where Store ='" & request.querystring("store") & "' order by [Category], name "
Set grs = gobjConn.Execute(gsSQL)
With hopes that I understand you correctly, you have id, quant, and article already in database and want to update the quant related to the ID. In that case:
In the loop that creates the form give each number input a name with the ID in the name (or if you just have one field just have the ID as the name). In your case:
<input type="number" name="qty<%=rs("ID")%>">
On the action page you then loop through all the fields and update accordingly, either you do a replace on the name to get the ID, or if you only use the ID as fieldname it works without replace:
For Each Item In Request.Form
fieldName = Item 'This is the ID (with above field name: qtyID where ID is the ID from the DB.
fieldValue = Request.Form(Item) 'This is the Quantity of that Article ID
articleid=replace(fieldName,"qty","")
sql="update table set qty=" + fieldValue + " where id=" + articleid
Next
That way you will go through all the fields in the form. I am also unsure if you need both ID and Article in where clause? Can one ID have many Articles or vice versa?
Related
I'm tring to do my first web app using python 3.4 and Bottle.
I'm tring do create a dropdown list using data from one table colled "Documenti" (using sqlite)
The table used has only two columns: ID_D (id) and Documents (name of document).
My need is that when a value is choosed, and the botton "search" cliked, Bottle opens a new page, using the ID_D value from the first table and printing info from a second table (colled "Master") thet has also a column colled ID_D.
I'm tring to do this using these codes:
first page with dropdwon list (using first table)
#route('/doc')
def Document():
conn = sqlite3.connect('db.db')
c = conn.cursor()
result = c.execute("SELECT ID_D FROM documenti;").fetchall()
c.close()
output = template('doc', rows=result)
return output
Second page, opened using the ID_D from the previous page to print info from the second table
#route('/docx', method='GET')
def docx():
if request.GET.get('search','').strip():
id = request.GET.get('docx', '').strip()
conn = sqlite3.connect('db.db')
c = conn.cursor()
c.execute("SELECT * FROM master WHERE ID_D LIKE ?;" (id))
result = c.fetchall()
c.close()
output = template('doc3', rows=result)
return output
Here there is my html code used...
in the page with the dropdown list:
<form action="/docx" method="GET">
<select name="docx"><option selected="selected" value="">Seleziona</option>
%for row in rows:
<option value="{{row}}">{{row}}</option>
%end
</select>
<input type="submit" name="search" value="search">
In the second page (where i wont to see info from the second table using as filter ID_D:
<table border="1">
%for row in rows:
<tr>
%for col in row:
<td>{{col}}</td>
%end
</tr>
%end
</table>
My codes doesn't work...the second page is blank...
Thanks to all for your help!
Mauro
EDIT:
for everyone...this is my working code:
#route('/docx', method='GET')
def docx():
id = request.GET.get('docx', '').strip()
conn = sqlite3.connect('db.db')
c = conn.cursor()
result = c.execute("SELECT * FROM master WHERE ID_D LIKE (?)", (id,)).fetchall()
c.close()
output = template('doc3', rows=result)
return output
Thanks to all guys!
I believe that if request.GET.get('search','').strip(): is evaluating to False and your view is thus returning None, which is the default behavior in Python. This makes sense as a submit button does not include itself in the query string. I would try this:
#route('/docx', method='GET')
def docx():
id = request.GET.get('docx', '').strip()
conn = sqlite3.connect('db.db')
c = conn.cursor()
c.execute("SELECT * FROM master WHERE ID_D LIKE ?;" (id))
result = c.fetchall()
c.close()
output = template('doc3', rows=result)
return output
If it still doesn't work, I would try right-clicking on the page (when opened in a browser) and selecting View Source and you should see a blank page, if you see something like this:
<table border="1">
</table>
then the SQL query is wrong.
I am trying to disable the default value for an asp select list, the default value being the string "null".
I want this to remain as the default, but when the user has selected another item in the select list to disable it as a selectable option.
The ASP code for the select list is below:
Response.Write "<Select name=""PersonID" & temporary.Fields("EventID") & class=""SelectText"" style=""width:100%"">" & vbCrLf &_
"<Option value=""NULL""></Option>"
Not sure why you would need to do this, usually you convert the empty value to null in your backend script if needed, or you can use something like jQuery to do this client-side, hoping that your browser has javascript enabled:
$("select").change(function(e){
$("option[value='NULL']:first",this).remove();
});
This will remove the first null option in your select list on change. If you need more help with javascript/jquery, you should tag your questions as so.
Alternatively to Zee Tee's answer, you could read the value on post back and determine its value...
<select id="personId" name="personId<%=eventId%>" class="selectText">
<option value="-1">-- Please select a value --</option>
<option value="1">......</option>
</select>
...and the postback code...
Dim personId, failForm
personId = Request.Form("PersonId")
failForm = (personId = -1)
I have asp.net grid view with default update and select columns (they are not converted to template columns)
Now I want to record whenever a user updates a row (i have a column in table: userlog which
can be displayed in the grid view but it is readonly)
I have tried to write my own update statement in GridView_RowUpdated event
but I am not getting the thing done, I wanted to append logged in user id, with
date post stamp, at the end of existing value in userlog column
Please help, currently I am doing the following, in RowUpdated event:
string sqlEL = "Select userlog from Schedule Where rowid=" + e.Keys[0].ToString();
string tmp = dao.GetSingle(sqlEL);
if (tmp == null || tmp == String.Empty)
tmp = ".";
string sqlUp = "Update Schedule set userlog='" + tmp + "' + '"
+ LogthisUser() + "' Where rowid=" + e.Keys[0].ToString();
dao.UpdateDB(sqlUp);
it was due to the fact that readonly column was a simple bound field
and in Asp.Net if you want to limit a column value in edit mode, still showing it
to the user in normal view, then it has to be template field, with EditItemTemplate
being removed
i have an input field whose value is coming from a variable, when i submit the form record insert as an empty row :(
if i check the view-source of my page it clearly prints the value but does not insert it.
Here is the Input Field:
<input name="uid" type="text" value="<%Response.Write(studentid)%>" disabled="disabled" />
Here is the Insert Code:
<%
if request.Form("MyRecord")="Insert" then
Set InsCom=Server.CreateObject("ADODB.Command")
InsCom.ActiveConnection=objConn
InsF = Trim(request.Form("uid"))
InsF = replace(InsF,"'","''")
InsCom.CommandText = "Insert into talent_hunt(uid)Values(?) "
InsCom.Parameters.Append InsCom.CreateParameter("#uid", adVarChar, adParamInput, 255, InsF)
InsCom.Execute
response.Write"Record Inserted Successfully!<br /><a href=""talent-hunt.asp"" />Go Back to main page</a>"
end if
%>
Please help...
Use readOnly instead of disabled.
ref. thread: How can I get the form value from a disabled <input> element
I'm pretty new with VB & ASPX.NET.
But I'm having a problem with showing the right info in a gridview.
Basically I've got a maintenance tool for an application. And I want to make it multi language.
This is a check for the language:
'setting the column name where to get the text resource from
Dim comment As String = "comment"
If (licentie.getlanguage() = "NL") Then
comment = "comment_NL"
End If
'Part of the sql query
sqlDataSourceGridView.SelectCommand = "select inst.categorie,inst.term_id,inst.term_result,inst." + comment + ", ETC.....
So far this works. But in my template I've got the following code in the gridview:
<asp:Label ID="LabelType" runat="server" Text='<%# Bind("Comment") %>' />
So my question is, How do I set the column 'comment_NL' when the language is set 'NL' in the bind?
Just give a Column Alias for inst.comment and inst.comment_NL by using AS in your Select Query
select inst.categorie,inst.term_id,inst.term_result,inst." + comment + " AS Comment, ETC.....