| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1040 人关注过本帖
标题:這樣的動態數據,我要如何提交到數據庫啊?
取消只看楼主 加入收藏
unix
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2005-12-28
收藏
 问题点数:0 回复次数:7 
這樣的動態數據,我要如何提交到數據庫啊?

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>下一步,工件信息錄入</title>
<%
dim lianluo
lianluo=session("lianluo")

%>
<center>
<h3><strong><font color="#FF0000"> <%=lianluo%> </font></strong></h3>

</center>
<form name="form1" method="post" action="gj_save.asp">
<script language=javascript type=text/javascript>
<!--
var RES_BT_DELETE = "刪除";
var isIE = (navigator.userAgent.indexOf("MSIE") != -1);
var fileIndex = 1;
function addFile() {
var spanId = "filespan";
var fileId = "upload" + (fileIndex++);
addInputFile(spanId, fileId);
}
function addInputFile(spanId, fileId) {
var span = document.getElementById(spanId);
if (span != null) {
var divObj = document.createElement("div"), lianluoObj, indexObj, tuhaoObj, taoObj, cailiaoObj, houObj, kuanObj, gaoObj, duObj, reObj, beizhuObj, delObj;
divObj.id = fileId;
if (isIE) {
lianluoObj = document.createElement("<input type=hidden>");
indexObj = document.createElement("<input type=text>");
tuhaoObj = document.createElement("<input type=text>");
taoObj = document.createElement("<input type=text>");
cailiaoObj = document.createElement("<input type=text>");
houObj = document.createElement("<input type=text>");
kuanObj = document.createElement("<input type=text>");
gaoObj = document.createElement("<input type=text>");
duObj = document.createElement("<input type=text>");
reObj = document.createElement("<input type=text>");
beizhuObj = document.createElement("<input type=text>");
delObj = document.createElement("<input type=button onclick=delInputFile('" + spanId + "','" + fileId + "')>");
} else {
lianluoObj = document.createElement("input");
lianluoObj.type = "hidden";
indexObj = document.createElement("input");
indexObj.type = "text";
tuhaoObj = document.createElement("input");
tuhaoObj.type = "text";
taoObj = document.createElement("input");
taoObj.type = "text";
cailiaoObj = document.createElement("input");
cailiaoObj.type = "text";
houObj = document.createElement("input");
houObj.type = "text";
kuanObj = document.createElement("input");
kuanObj.type = "text";
gaoObj = document.createElement("input");
gaoObj.type = "text";
duObj = document.createElement("input");
duObj.type = "text";
reObj = document.createElement("input");
reObj.type = "text";
beizhuObj = document.createElement("input");
beizhuObj.type = "text";
delObj = document.createElement("input");
delObj.type = "button";
delObj.setAttribute("onclick", "delInputFile('" + spanId + "','" + fileId + "')", 0);
}
lianluoObj.id = "lianluo";lianluoObj.value = 0;lianluoObj.name = "lianluo";
indexObj.name = "index";indexObj.id = "index";indexObj.size = "6";indexObj.value = fileIndex;
tuhaoObj.name = "tuhao";tuhaoObj.id = "tuhao";tuhaoObj.size = "18";
taoObj.name = "tao";taoObj.id = "tao";taoObj.size = "8";
cailiaoObj.name = "cailiao";cailiaoObj.id = "cailiao";cailiaoObj.size = "8";
houObj.name = "hou";houObj.id = "hou";houObj.size = "8";
kuanObj.name = "kuan";kuanObj.id = "kuan";kuanObj.size = "8";
gaoObj.name = "gao";gaoObj.id = "gao";gaoObj.size = "8";
duObj.name = "du";duObj.id = "du";duObj.size = "8";
reObj.name = "re";reObj.id = "re";reObj.size = "8";
beizhuObj.name = "beizhu";beizhuObj.id = "beizhu";beizhuObj.size = "20";
delObj.value = RES_BT_DELETE;
divObj.appendChild(lianluoObj);
divObj.appendChild(indexObj);
divObj.appendChild(tuhaoObj);
divObj.appendChild(taoObj);
divObj.appendChild(cailiaoObj);
divObj.appendChild(houObj);
divObj.appendChild(kuanObj);
divObj.appendChild(gaoObj);
divObj.appendChild(duObj);
divObj.appendChild(reObj);
divObj.appendChild(beizhuObj);
divObj.appendChild(delObj);
span.appendChild(divObj);
}
}
function delInputFile(spanId, fileId) {
var span = document.getElementById(spanId);
var divObj = document.getElementById(fileId);
if (span != null && divObj != null) {
span.removeChild(divObj);
}
}
//-->
</script>
<meta content="MSHTML 6.00.2800.1528" name=GENERATOR>
</head>
<body onkeydown="quickadd(event)">
<form name=form1 id=form1 action="" method=post onSubmit="return checkCnt();">
<table height=20 cellSpacing=1 cellPadding=8 width="90%" align=center>
<tbody>
<tr>
<TD id=filespan noWrap>
<div id=0>
<input name="11" type="text" id="11" size="6" value="序號" disabled><input name="22" type="text" id="22" size="18" value="圖號" disabled><input name="33" type="text" id="33" size="8" value="套" disabled><input name="44" type="text" id="44" size="8" value="材料" disabled><input name="55" type="text" id="55" size="8" value="厚" disabled><input name="66" type="text" id="66" size="8" value="寬" disabled><input name="77" type="text" id="77" size="8" value="長" disabled><input name="88" type="text" id="88" size="8" value="鍍" disabled><input name="99" type="text" id="99" size="8" value="熱" disabled><input name="00" type="text" id="00" size="20" value="備注" disabled>
</div>
<div id=1>
<input name="index" type="text" id="index" value="1" size="6"><input name="tuhao" type="text" id="tuhao" size="18"><input name="tao" type="text" id="tao" size="8"><input name="cailiao" type="text" id="cailiao" size="8"><input name="hou" type="text" id="hou" size="8"><input name="kuan" type="text" id="kuan" size="8"><input name="gao" type="text" id="gao" size="8"><input name="du" type="text" id="du" size="8"><input name="re" type="text" id="re" size="8"><input name="beizhu" type="text" id="beizhu" size="20"><INPUT id=btnAdd onclick=addFile() type=button value=添加>
</div>
</TD>
</tr>
<tr>
<td noWrap align=center>
<input name="submit" type="submit" value="提交">
<input name="reset" type="button" value="取消">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
<script language="JavaScript">
cnt = 0;
function checkCnt(){
document.form1.Submit.disabled=true;
cnt++;
if (cnt!=1){
alert('正在提交數據. Please Wait');
return false;
}
}
function quickadd(event)
{
if(event.altKey && event.keyCode == 9)
{
if (cnt==0){
this.addFile();
}else{
alert('正在提交數據. Please Wait');
}
}
}
</script>



按ait+s鍵,可以增加行。

可是這樣的數據我要如何提交到數據庫呢?
图片附件: 游客没有浏览图片的权限,请 登录注册


數據是SQL,數據類型如圖

[此贴子已经被作者于2006-2-18 14:23:00编辑过]

搜索更多相关主题的帖子: javascript html content 下一步 action 
2006-02-18 14:20
unix
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2005-12-28
收藏
得分:0 
以下是引用griefforyou在2006-2-18 15:08:00的发言:
没问题呀,你提交一下看看就知道了,每一列的数据是用逗号分隔的,你可以用split拆分

我想是你理解錯我的意思了!
我想問的是如何將數據提交到數據庫?

如果數據只有一行的話就好辦,但是多行的時候用什麼方法呢?保存文件要怎麼樣寫呢?



<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--#include file="xh_conn.asp"-->


<%
lianluo=trim(request.form("lianluo"))

if lianluo="" then
response.write "error <BR>"
response.end
else

set rs=server.createobject("adodb.recordset")
sql="select max(item) from gojianxinxi group by lianluo having lianluo="&lianluo
rs.open sql,db,1,1
if rs.eof and rs.bof then
b=1
else
b=rs(0)
b=Cint(b)
b=b+1
end if
rs.close

rs.open "gojianxinxi",db,1,3
rs.addnew
rs("lianluo")=lianluo
rs("item")=b
rs("tuhao")=trim(request.form("tuhao"))
rs("tu")=trim(request.form("tu"))
rs("cailiao")=trim(request.form("cailiao"))
rs("hou")=trim(request.form("hou"))
rs("kuan")=trim(request.form("kuan"))
rs("gao")=trim(request.form("gao"))
rs("du")=trim(request.form("du"))
rs("re")=trim(request.form("re"))
rs("beizhu")=trim(request.form("beizhu"))
rs.update
rs.close
set rs=nothing

end if
response.write "<script language=javascript>alert('输入完毕');history.back(-1)</script>"
%>

上面的代碼是在只有一行數據時,提交到數據庫的代碼。

[此贴子已经被作者于2006-2-20 8:48:28编辑过]

2006-02-18 16:37
unix
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2005-12-28
收藏
得分:0 
嗯。謝謝

我試試。

如果數據很多時會有問題不?一般提交一次數據會在150行左右。

[此贴子已经被作者于2006-2-18 17:27:22编辑过]

2006-02-18 17:20
unix
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2005-12-28
收藏
得分:0 
以下是引用griefforyou在2006-2-18 18:24:00的发言:
一般大数据量的提交可以通过格式化的txt或csv文件上传来导入数据库,这样一行一行填太麻烦了,而且万一因为网络或其它原因提交不成功,数据不是白输了?

這個要昨整呢?
不好意思,我剛接觸ASP不久。

2006-02-20 08:23
unix
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2005-12-28
收藏
得分:0 

<meta http-equiv="Content-Type" content="text/html; charset=big5">
<!--#include file="xh_conn.asp"-->


<%
lianluo=trim(request.form("lianluo"))

if lianluo="" then
response.write "error <BR>"
response.end
else

set rs=server.createobject("adodb.recordset")
sql="select max(item) from gojianxinxi group by lianluo having lianluo="&lianluo
rs.open "gojianxinxi",db,1,3
rs.addnew
rs("lianluo")=lianluo

lianluo = request.form("lianluo")
item = request.form("item")
tuhao = request.form("tuhao")
tao = request.form("tao")
cailiao = request.form("cailiao")
hou = request.form("hou")
kuan = request.form("kuan")
gao = request.form("gao")
du = request.form("du")
re = request.form("re")
beizhu = request.form("beizhu")


lianluo = split(lianluo,",")
item = split(item,",")
tuhao = split(tuhao,",")
tao = split(tao,",")
cailiao = split(cailiao,",")
hou = split(hou,",")
kuan = split(kuan,",")
gao = split(gao,",")
du = split(du,",")
re = split(re,",")
beizhu = split(beizhu,",")

for i = 0 to ubound(lianluo)
sql = "insert into gojianxinxi(lianluo,tuhao,tao,cailiao,hou,kuan,gao,du,re,beizhu) values('"&trim(lianluo(i))&"','"&trim(tuhao(i))&"','"&trim(tao(i))&"','"&trim(cailiao(i))&"','"&trim(hou(i))&"','"&trim(kuan(i))&"','"&trim(gao(i))&"','"&trim(du(i))&"','"&trim(re(i))&"','"&trim(beizhu(i))&"')"
db.execute sql
next

rs.update
rs.close
set rs=nothing

end if
response.write "<script language=javascript>alert('輸入完畢');history.back(-1)</script>"
%>

這樣總算可以成功提交了。可是提交後到SQL後台一看,全亂套了。!!!!!

SQL裡gojianxinxi表裡的lianluo只取了一個,SQL裡的item全是null.

我要的結果是每行liankuo取相同的一個,item是自動編號的,如果一行的話,那麼item就是1,2行的話item就是1,2...。

當換了lianluo時,item又是從1開始取的。

[此贴子已经被作者于2006-2-21 8:13:43编辑过]

2006-02-20 16:21
unix
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2005-12-28
收藏
得分:0 

我頂一下。

2006-02-20 17:50
unix
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2005-12-28
收藏
得分:0 
UP
2006-02-21 08:14
unix
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2005-12-28
收藏
得分:0 
2006-02-21 12:35
快速回复:這樣的動態數據,我要如何提交到數據庫啊?
数据加载中...
 
   



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

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