ASP FAQs and Answers (6)

Source: Internet
Author: User
Tags chr getdate query servervariables trim
Answer | Question 1. Prevent users from accessing the page directly (prevent self-made form submission and access directly via link)
function Checkprepage ()
Url=request. ServerVariables ("Http_referer")
Url=trim (replace (URL, "http://", ""))
Url=trim (Url,len (Request). ServerVariables ("SERVER_NAME")))
If Url<>trim (request. ServerVariables ("SERVER_NAME")) then
Response. Write ("Please visit this site in a proper way")
Response. End ()
End If
End Function



2. Through the two function can realize the picture, the text at the same time submit processing.
Function binarytostring (str)
Strto = ""
For I=1 to LenB (str)
If AscB (MidB (str, I, 1)) > 127 Then
Strto = Strto & Chr (ASCB (MidB (str, I, 1)) *256+ASCB (MidB (str, i+1, 1))
i = i + 1
Else
Strto = Strto & Chr (AscB (MidB (str, I, 1))
End If
Next
Binarytostring=strto
End Function

function Gainformdata (n)
Dim formsize,formdata,divider,datastart,dataend
ReDim MyData (N-1)
Formsize = Request.TotalBytes
Formdata = Request.BinaryRead (formsize)
For I=1 to N
Bncrlf = ChrB (+) & ChrB (10)
Divider = LeftB (FORMDATA,CLNG (InstrB (FORMDATA,BNCRLF))-1)
Datastart = InstrB (Formdata,bncrlf & Bncrlf) +4
Dataend = InstrB (datastart+1,formdata,divider)-datastart-2
MyData (i-1) = MidB (formdata,datastart,dataend)
FORMDATA=RIGHTB (FORMDATA,CLNG (FORMSIZE-INSTRB (Datastart+1,formdata,divider)) +1)
Formsize=lenb (Formdata)
Next
Gainformdata=mydata
End Function

Demo:
A.htm:
<form name= "Form1" method= "Post" action= "b.asp" enctype= "Multipart/form-data" >
<textarea name= "TXT" ></textarea>
<input type= "File" name= "file" >
<input type= "Submit" name= "Submission" value= "submitted" >
</form>

B.asp:
' Link Database
Data=gainfromdata (2)
RS ("TXT") =binarytostring (data (0))
RS ("img"). Appendchunk=data (1)



3. Pop-up prompts to determine and cancel how to do
Onclick= ' {if confirm (' OK to delete selected record? ') {this.document.inbox.submit (); return true;} return false;} "



4. Combination of query optimization, thank you
sql = "SELECT * from book where bname like '%" & txtbname. Text & "% ' and bauthor like '%" & Txtauthor. Text & "% ' and bpublish like '%" & txtpublish. Text & "% ' and bdescription like '%" & txtdescription. Text & "% ' ORDER by bookid Desc"

Combination query, there are four combinations of conditions, so write is not a low efficiency, how can I optimize it?
Thank you.

Analysis, in SQL, with like is more time-consuming, so it is best to use less.

At the same time, four text boxes, enter the condition is, there will be no input conditions, there will be like "%" situation, in fact, this is tantamount to this condition is not.

So, write the code that generates the SQL statement more,
Dim Wherestr As String
If Txtbname. Text<> "" Then
Wherestr= "bname like '%" & txtbname. Text & "%"
ELSE IF ....
.....
ENDIF
This is a probability problem, if four full input words, is the same, but if only input one of the questions, the speed will be faster than yours!

sql = "SELECT * FROM book where"
If Txtbname. Text <> "" Then
sql = SQL & "bname like '%" & txtbname. Text & "%"
ElseIf Txtauthor. Text <> "" Then
sql = SQL & "Bauthor like '%" & Txtauthor. Text & "%"
ElseIf Txtpublish. Text <> "" Then
sql = SQL & "Bpublish like '%" & txtpublish. Text & "%"
ElseIf txtdescription. Text <> "" Then
sql = SQL & "bdescription like '%" & txtdescription. Text & "%"
End If



5. How to prevent refreshing
<script language= "JavaScript" >
Document.onkeydown = function () {
if (event.keycode==116) {
event.keycode=0;
Event.returnvalue = false;
}
}
Document.oncontextmenu = function () {event.returnvalue = false;}
</SCRIPT>
Page has been blocked from refreshing



6.sql server with: sql = "Update reg set Dealtime=getdate () where id=" & Request.QueryString ("id")
Because there is no now () function in SQL Server, instead of the GETDATE ()
So you're going to make an error.
Access does not have this function:)
Only date () and now ()



7. Methods of linking to other databases (*.dbf,*.txt,excel,foxpro, etc.)----collection
2002-10-30 18:41:05 Views: 145

' Link DBF file
<%
' Create a Connection object
Set conn = Server.CreateObject ("ADODB. Connection ")
Driver = "Driver={microsoft Visual FoxPro Driver};"
SourceType = "SOURCETYPE=DBF;"
DBPath = "sourcedb=" & Server.mappa



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.