推薦:ASP中限制表單的多次重復(fù)提交在Internet上我們每天都會遇到數(shù)不清的表單,也看到其中大部分并沒有限制用戶多次提交同一個表單。缺乏這種限制有時候會產(chǎn)生某些預(yù)料不到的結(jié)果,如重復(fù)訂閱郵件服務(wù)或重復(fù)投票等。 本文介紹在ASP應(yīng)用中防止用戶在當前會話期間多次提交同一表單的一個簡單方
批量錄入在數(shù)據(jù)庫的應(yīng)用中比較廣泛的,關(guān)于批量錄入的方法也有好多種。下面我就結(jié)合我實際中的應(yīng)用,談一下兒我是怎么實現(xiàn)的。主要用到的是form的集合的概念,通過循環(huán)取的所有的集合內(nèi)數(shù)據(jù)�?紤]到大家看著方便,我把它集成到了一個頁面。
下面是具體的代碼:
| 以下為引用的內(nèi)容:
<% ’向數(shù)據(jù)庫寫入數(shù)據(jù) SUB writeData() dim recCnt,i dim fieldName1,fieldName2,fieldName3 dim conn dim sqlStr,connStr connStr="Provider=SQLOLEDB.1;Initial Catalog=myDatabase;Data Source=myhon;User Id=sa;PASSWORD=" set conn=Server.CreateObject("ADODB.Connection") conn.open connStr ’建立數(shù)據(jù)庫連接 recCnt=request.form("stu_num").count ’取得共有多少條記錄 ’批量錄入數(shù)據(jù) for i=1 to recCnt fieldName1=trim(request.form("fieldName1")(i)) fieldName2=trim(request.form("fieldName2")(i)) fieldName3=trim(request.form("fieldName3")(i)) sqlStr="insert into myTable(fieldName1,fieldName2,fieldName3) values(’" sqlStr=sqlStr & fieldName1 & "’,’" sqlStr=sqlStr & fieldName2 & "’,’" sqlStr=sqlStr & fieldName3 & "’)" ’response.write sqlStr conn.execute(sqlStr) next END SUB ’顯示成批錄入的界面 SUB InputData() dim recCnt,i %> <form name="bathInputData" action="" method="post"> <% recCnt=cint(request.form("recCnt")) for i=1 to recCnt %> <input type="text" name="fieldName1"> <input type="text" name="fieldName2"> <input type="text" name="fieldName3"> <% next %> <br> <input type="submit" name="action" value="提交"> </form> <% END SUB ’指定要批量錄入多少條記錄 SUB assignHowMuch() %> <!------指定要錄入多少條記錄--------------> <form name="form1" action="" method="post">
您要錄入的記錄的條數(shù):<input type="text" name="recCnt"> <input type="submit" name="action" value="下一步>>"> </form> <% END SUB if request.form("action")="下一步>>" then Call InputData() ’顯示成批錄入界面 elseif request.form("action")="提交" then Call writeData() ’向數(shù)據(jù)庫批量寫入數(shù)據(jù) else Call assignHowMuch() ’顯示指定錄入多少條記錄的界面 end if %>
|
分享:ASP多重查詢的解決方案我們經(jīng)常會遇到多重查詢問題,而長長的SQL語句往往讓人丈二和尚摸不著頭腦。特別是客戶端部分填入查詢條件時,如用普通方法將更是難上加難。 以下巧妙地利用where 1=1的恒等式(事實上很多,讓它值為TRUE即可)解決此問題。 正文概要 'subject 信息標題 'com