《实例精粹ASP》中部分源代码
源代码在线查看: proaddsave.asp
Dim strSQL, cmdObj, rsObj
Dim nID, nProductType, nMemberPrice, nMarketPrice
'获取表单数据
nID = RealString(Request.Form("id"))
nProductType = Cint(Request.Form("ProductType"))
nMemberPrice = Request.Form("memberPrice")
nMarketPrice = Request.Form("marketPrice")
if not IsNumeric(nMemberPrice) then nMemberPrice = "1"
if not IsNumeric(nMarketPrice) then nMarketPrice = "1"
'创建对象
Set cmdObj = Server.CreateObject("ADODB.Command")
Set rsObj = Server.CreateObject("ADODB.RecordSet")
cmdObj.CommandText = "SELECT top 1 * FROM product WHERE Id=null" ' ORDER by id desc"
cmdObj.CommandType = adCmdText
cmdObj.ActiveConnection = conn
call rsObj.Open(cmdObj, , adOpenKeyset, adLockOptimistic)
'添加数据
rsObj.AddNew()
rsObj("ProductType") = nProductType
rsObj("name") = Request.Form("name")
rsObj("memberPrice") = nMemberPrice
rsObj("marketPrice") = nMarketPrice
rsObj("introduce") = Request.Form("introduce")
rsObj("remark") = Request.Form("remark")
'更新数据库
rsObj.Update()
'关闭连接,将连接放入连接池
rsObj.Close
set rsObj = nothing
CloseConn()
%>
alert("添加成功!");
window.location = "productList.asp";
-->