标题:from中的数据如何循环的存入SQL数据库
只看楼主
hytsky
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-5-3
结帖率:0
已结贴  问题点数:20 回复次数:2 
from中的数据如何循环的存入SQL数据库
我的提交页是这样的
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>原料入库单</title>
<link href="../css/material.css" type="text/css" rel="stylesheet" />
<style type="text/css">
<!--
.STYLE1 {
    font-size: 18px;
    font-weight: bold;
}
.STYLE2 {
    font-size: 14px;
    font-weight: bold;
}
.STYLE6 {
    color: #FF0000;
    font-size: 10pt;
}
.STYLE9 {color: #0000FF; font-weight: bold; font-size: 12px; }
-->
</style>
<%
Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "No-Cache"
%>
<script language="JavaScript">
function addOrderRow(tab,rowNum,colNum,obj,addType)
{
var detailbody=document.getElementById(tab);
var row = document.createElement("tr");
var newrow=obj.parentNode.parentNode.innerHTML;
if(addType=='add'){
var row = detailbody.insertRow();
 for(var i=0;i<obj.parentNode.parentNode.childNodes.length;i++){
  var cell=row.insertCell();
  cell.innerHTML=obj.parentNode.parentNode.childNodes[i].innerHTML;
  //如果表单中有值就清空
  for(var k=0;k<cell.childNodes.length;k++){
   if (cell.childNodes[k].type == 'text') { cell.childNodes[k].value = ''; }
   if (cell.childNodes[k].type == 'textarea') { cell.childNodes[k].value = ''; }
   if (cell.childNodes[k].type == 'checkbox') { cell.childNodes[k].checked = false; }
   if (cell.childNodes[k].type == 'radio') { cell.childNodes[k].checked = false; }
   if (cell.childNodes[k].type == 'select-multiple') { cell.childNodes[k].selectedIndex = -1; }
   if (cell.childNodes[k].type == 'select-one') { cell.childNodes[k].selectedIndex = -1; }
  }
 }
  obj.parentNode.parentNode.childNodes[0].innerHTML+='<input type=hidden id=text'+(detailbody.childNodes.length+1)+'>';
}else if(addType=='copy'){
//copy
var row = detailbody.insertRow();
for(var i=0;i<obj.parentNode.parentNode.childNodes.length;i++){
var cell=row.insertCell();
cell.innerHTML=obj.parentNode.parentNode.childNodes[i].innerHTML;
}
obj.parentNode.parentNode.childNodes[0].innerHTML+='<input type=hidden id=text'+(detailbody.childNodes.length+1)+'>';
}else{
//delete
if(confirm("Are you sure to delete this record?")){
    obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
}else{
return false;
}
}
//只显示最后一个add按钮
var leg = detailbody.childNodes.length;
if(leg>1){
for(var j=0;j<leg-2;j++){
document.getElementsByName("btnAdd")[j].style.visibility="hidden";
}
  document.getElementsByName("btnAdd")[leg-2].style.visibility="visible";
   }
//显示除第一个外所有delete按钮
if(leg>1){
  for(var j=1;j<leg-1;j++){
document.getElementsByName("btnDelete")[j].style.visibility="visible";
}
}
        }
</script>
</head>

<body id="material_body">
  <div align="center" class="STYLE1">数据录入</div>
<form name="materialform_in" id="materialform_in" action="../material/material_in.asp" method="post">
     <table align="center" width="520">
       <tr align="center">
          <td align="right">
             <span class="STYLE6">
                YLRK<input type="text" style= "border:solid 0px;color:#FF0000" name="material_id" id="material_id" class="table_id" size="13" value="<%=year(now())%><%=month(now())%><%=day(now())%><%=hour(now())%><%=minute(now())%><%=second(now())%>" readonly="readonly" />
             </span>
          </td>
       </tr>
       <tr>
          <td align="center" class="STYLE2">原料入库登记表</td>
       </tr>
     </table>
<div id="outlineChildaaa" style="cursor:auto" >
<table align="center" border="1" cellpadding="1" cellspacing="0" bordercolor="#666666" width="520" id="detailItem">
 <tbody id="detailItemBody" align="center">
  <tr bgcolor="#FFFFFF" align="center">
    <td height="30" width="70">品 名</td>
    <td width="100">规 格</td>
    <td width="80">盘 数</td>
    <td width="70">每盘重量</td>
    <td width="95">总重量</td>
    <td width="95">操作</td>
  </tr>
  <tr bgcolor="#FFFFFF" align="center" id="tr1">
    <td height="25" width="70"  id="td1">
      <select name="myselect_pm" id="myselect_pm">
        <option selected="selected">请选择</option>
        <option value="岩章" >岩章</option>
        <option value="真章" >真章</option>
        <option value="长爪" >长爪</option>
        <option value="墨鱼" >墨鱼</option>
        <option value="鱿鱼" >鱿鱼</option>
        <option value="杂鱼" >杂鱼</option>
      </select>
    </td>
    <td width="100" nowrap="">
      <select name="myselect_gg" id="myselect_gg">
        <option value="50g以下" selected="selected">50g以下</option>
        <option value="50g-80g">50g-80g</option>
        <option value="80g-120g">80g-120g</option>
        <option value="120g-200g">120g-200g</option>
        <option value="200g-300g">200g-300g</option>
        <option value="300g-500g">300g-500g</option>
        <option value="500g-800g">500g-800g</option>
        <option value="800g-1000g">800g-1000g</option>
        <option value="1000g-1200g">1000g-1200g</option>
        <option value="1200g-1500g">1200g-1500g</option>
        <option value="1500g-2000g">1500g-2000g</option>
        <option value="2000g-2500g">2000g-2500g</option>
        <option value="2500g以上">2500g以上</option>
        <option value="150g以下">150g以下</option>
        <option value="150g-250g">150g-250g</option>
        <option value="250g-350g">250g-350g</option>
        <option value="350g以上">350g以上</option>
      </select>
    </td>
    <td width="80" nowrap=""><input type="text" size="8"  name="material_disk" id="material_disk"/></td>
    <td width="70" nowrap="">10kg/盘</td>
    <td width="95" nowrap=""><input type="text" size="7" name="material_weight" id="material_weight" /> kg</td>
    <td width="95" nowrap="">
      <input type="button" onclick="addOrderRow('detailItemBody',2,11,this,'add')" value="增加" id="btnAdd1" name="btnAdd"/>
<input type="button" onclick="addOrderRow('detailItemBody',2,11,this,'delete')" value="删除" id="btnDelete" name="btnDelete" style="visibility:hidden "/>
    </td>
  </tr>
  </tbody>
</table>
</table>
    <table width="520" align="center">
      <tr align="center">
      <td height="25" width="260">
         <span class="STYLE9"> 入库人</span>
         <input type="text" size="10" name="material_inname" id="material_inname" />         
      </td>
        <td width="260">
          <span class="STYLE9">存放
          <input type="text" size="5" name="material_warehouse" id="material_warehouse" />
        号仓库</span>        </td>
      </tr>
</table>
</table>
    <table width="520" align="center">
      <tr align="center">
        <td><input type="submit" value="提交入库" /></td>
      </tr>
</table>
</div>
</form>
</body>
</html>

数据处理页这是样的
<%
set conn=server.createobject("ADODB.connection")
conn.Open "PROVIDER=SQLOLEDB;DATA SOURCE=USERDEL-R59XKAX\SQLEXPRESS;UID=bgtx;PWD=123456;DATABASE=bgtxdatabase;"
set rs=server.createobject("adodb.recordset")
for i=0 to Request.Form("materialform_in").count
rs.open "select * from bgtx_db_material_detail",conn,1,3
rs.addnew
rs("material_id")=request("material_id")
rs("material_name")=request.form("myselect_pm")
rs("material_size")=request.form("myselect_gg")
rs("material_disk")=request.form("material_disk")
rs("material_weight")=request.form("material_weight")
rs("material_time")=year(now())&month(now())&day(now())
rs("material_inname")=request("material_inname")
rs("material_warehouse")=request("material_warehouse")
rs.update
next
conn.close
set conn=nothing
response.write "记录添加成功!"
%>

请问要怎么修改才能让表单的数据都能顺序的存入数据库中,而不会将所有的数据存放在同一行里,菜鸟询问请老鸟帮忙
搜索更多相关主题的帖子: SQL数据库 content PUBLIC 入库单 style 
2016-05-03 14:42
hu9jj
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:红土地
等 级:贵宾
威 望:396
帖 子:11713
专家分:43267
注 册:2006-5-13
得分:20 
试试
<%
set conn=server.createobject("ADODB.connection")
conn.Open "PROVIDER=SQLOLEDB;DATA SOURCE=USERDEL-R59XKAX\SQLEXPRESS;UID=bgtx;PWD=123456;DATABASE=bgtxdatabase;"
set rs=server.createobject("adodb.recordset")
rs.open "select * from bgtx_db_material_detail",conn,1,3
for i=0 to Request.Form("materialform_in").count
rs.addnew
rs("material_id")=request("material_id")
rs("material_name")=request.form("myselect_pm")
rs("material_size")=request.form("myselect_gg")
rs("material_disk")=request.form("material_disk")
rs("material_weight")=request.form("material_weight")
rs("material_time")=year(now())&month(now())&day(now())
rs("material_inname")=request("material_inname")
rs("material_warehouse")=request("material_warehouse")
rs.update
next
conn.close
set conn=nothing
response.write "记录添加成功!"
%>

活到老,学到老! http://www. E-mail:hu-jj@
2016-05-08 10:19
hu9jj
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:红土地
等 级:贵宾
威 望:396
帖 子:11713
专家分:43267
注 册:2006-5-13
得分:0 
将连接语句放在循环体之外。

活到老,学到老! http://www. E-mail:hu-jj@
2016-05-08 10:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-464347-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.077863 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved