如何插入具有相同字段名称Request.Form的多个行

时间:2013-07-26 05:59:46

标签: ms-access asp-classic

我有一个从数据库中获取字段值的表单,所有字段都有自己的名称,并且记录从数据库中循环。 见下面的代码

<%
While Not RStmtbl.EOF
%>
<tr>
<td><input type="text" value="<% Response.Write(Rstmtbl("tdate"))%>" name="tdate_insert" readonly /></td>
<td><input type="text" value="<% Response.Write(Rstmtbl("day"))%>" name="day_insert" readonly /></td>
<td><input type="text" value="<% Response.Write(Rstmtbl("class"))%>" name="class_insert" readonly /></td>
<td><input type="text" value="<% Response.Write(Rstmtbl("pno"))%>" name="pno_insert" readonly /></td>
<td><input type="text" value="<% Response.Write(Rstmtbl("subject"))%>" name="subject_insert" readonly /></td>
<td><input type="text" value="<% Response.Write(Rstmtbl("teacher"))%>" name="teacher_insert" readonly /></td>
<td>
<select name="status_insert">
<option selected>Choose Status</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<input type="hidden" value="<% Response.Write(formno) %>" name="uid_insert">
<input type="hidden" value="<% Response.Write(Now) %>" name="sdate_insert">
</td>
</tr>
<%
RStmtbl.Movenext
Wend
%>

此时一切都很好,HTML输出来自访问数据库的所有记录, 但是当我插入此表单时会出现问题。

以下是插入代码

<%
if request.Form("TcfRecord")="Insert" then
Set InsCom=Server.CreateObject("ADODB.Command")
InsCom.ActiveConnection=objConn

InsTD = Trim(request.Form("tdate_insert"))
InsTD = replace(InsTD,"'","''")

InsTD2 = Trim(request.Form("day_insert"))
InsTD2 = replace(InsTD2,"'","''")

InsCL = Trim(request.Form("class_insert"))
InsCL = replace(InsCL,"'","''")

InsPI = Trim(request.Form("pno_insert"))
InsPI = replace(InsPI,"'","''")

InsSBI = Trim(request.Form("subject_insert"))
InsSBI = replace(InsSBI,"'","''")

InsTI = Trim(request.Form("teacher_insert"))
InsTI = replace(InsTI,"'","''")

InsSI = Trim(request.Form("status_insert"))
InsSI = replace(InsSI,"'","''")

InsUI = Trim(request.Form("uid_insert"))
InsUI = replace(InsUI,"'","''")

InsDI = Trim(request.Form("sdate_insert"))
InsDI = replace(InsDI,"'","''")

InsCom.CommandText = "Insert into time_table_status(tdate, day, class, pno, subject, teacher, status, uid, submit_date)Values(?,?,?,?,?,?,?,?,?)"
InsCom.Parameters.Append InsCom.CreateParameter("@tdate_insert", adVarChar, adParamInput, 255, InsTD)
InsCom.Parameters.Append InsCom.CreateParameter("@day_insert", adVarChar, adParamInput, 255, InsTD2)
InsCom.Parameters.Append InsCom.CreateParameter("@class_insert", adVarChar, adParamInput, 255, InsCL)
InsCom.Parameters.Append InsCom.CreateParameter("@pno_insert", adVarChar, adParamInput, 255, InsPI)
InsCom.Parameters.Append InsCom.CreateParameter("@subject_insert", adVarChar, adParamInput, 255, InsSBI)
InsCom.Parameters.Append InsCom.CreateParameter("@teacher_insert", adVarChar, adParamInput, 255, InsTI)
InsCom.Parameters.Append InsCom.CreateParameter("@status_insert", adVarChar, adParamInput, 255, InsSI)
InsCom.Parameters.Append InsCom.CreateParameter("@uid_insert", adVarChar, adParamInput, 255, InsUI)
InsCom.Parameters.Append InsCom.CreateParameter("@sdate_insert", adVarChar, adParamInput, 255, InsDI)

InsCom.Execute

end if
%>

但它会返回错误。

  

Microsoft JET数据库引擎(0x80040E14)INSERT INTO中的语法错误   言。

我想插入具有相同输入字段名称的多行,在搜索时我找到了这个解决方案。但它也不起作用......

<%
For Each item in Request.Form

' Above Insert Code

Next
%>

请告诉我INSERT声明有什么问题。感谢

1 个答案:

答案 0 :(得分:2)

Dayclass都是reserved words。将它们括在方括号中。

InsCom.CommandText = "Insert into time_table_status(tdate, [day], [class], pno, subject, teacher, status, uid, submit_date)Values(?,?,?,?,?,?,?,?,?)"