如何使用asp classic和vbscript在mssql db中基于单选框插入多行中的值

时间:2015-03-12 15:20:08

标签: vbscript asp-classic

我正在使用asp classic(attn.asp)创建一个考勤注册页面。在数据库中我创建了3列(staffid,attn_status,attn_dt)。

staffid:店员唯一身份证值。 attn_status:存储价值如P(现在)& A(缺席)& L(假)。 attn_dt:存储出勤日期值。

页面中的

我可以使用while / wend显示行中的所有员工以及状态单选按钮。

enter image description here

我的代码如下(page1.asp):

<from action="page2.asp">
<td style="text-align:left;"> 
<%= objRs1("Aname") %><%= objRs1("Aid") %><input type="hidden" name="usrid" value="<%= objRs1("Aid") %>"><input type="hidden" name="sattdt" value="<%= adt %>">
</td>

在上面,检索了员工姓名,身份和日期

的值
<td style="text-align:center;"> 
<input type="radio" name="<%= objRs1("Aid") %>" id="P" value="P"></input>
</td>
<td style="text-align:center;"> 
<input type="radio" name="<%= objRs1("Aid") %>" id="A" value="A"></input>
</td>
<td style="text-align:center;"> 
<input type="radio" name="<%= objRs1("Aid") %>" id="L" value="L"></input>
</td>

在上面的表格中,每条记录都有唯一的广播组名称(即id)。 我已经使用了while / wend循环,但是当我提交上面的表单时,它只将第一个记录值传递给下一页意味着循环不起作用。这就是为什么它只保存一个数据库的值。请帮助我,我错了,怎么做。

在&#34; page2.asp&#34;中,我编写了代码,将以上提交的值保存在mssql db的多行中:

<%
Dim radio, Staffid, attdt
radio = Split(Request.Form("usrid"), ",")(0)
Staffid = Split(Request.Form("usrid"), ",")(0)
attdt = Split(trim(Request.Form("sattdt")), ",")(0)
%>

<%

Dim objRS, objCmd, str
For Each  radio in Request.Form("group1")
Set objCmd  = Server.CreateObject("ADODB.Command")
Set Objrs   = Server.CreateObject("ADODB.Recordset")

str = "insert into Staff_attendance (staff_Aid, staff_attn_dt, staff_attn_status) values(?,?,?)"

With objCmd
.ActiveConnection = MM_connDUdirectory_STRING
.CommandText = str
.CommandType = adCmdText

.Parameters.Append(.CreateParameter("@param4g", adInteger, adParamInput, ,Staffid))
.Parameters.Append(.CreateParameter("@paramg16", adVarChar, adParamInput, len(attdt)))
.Parameters.Append(.CreateParameter("@paramg16q", adVarChar, adParamInput, len(radio)))


.Parameters("@param4g").Value = Staffid
.Parameters("@paramg16").Value = attdt
.Parameters("@paramg16q").Value = radio

end with 
Set objRS = objCmd.Execute()
 Next
%>

使用上面的代码,在db中只添加了一行。

请帮助我在多行中保存ID值。

0 个答案:

没有答案