0

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

<%
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 输出 access 数据库中的所有记录,但是当我插入此表单时出现问题。

这是插入代码

<%
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 语句有什么问题。谢谢

4

1 回答 1

2

Day并且class都是保留字。将它们括在方括号中。

InsCom.CommandText = "Insert into time_table_status(tdate, [day], [class], pno, subject, teacher, status, uid, submit_date)Values(?,?,?,?,?,?,?,?,?)"
于 2013-07-26T06:12:57.307 回答