รบกวนถามการรับข้อมูลทีละหลายๆ เรคคอร์ด ครับ คือเวลาออกแบบรับข้อมูลเป็นรูปแบบตาราง
ตัวอย่างการ Insert ข้อมูลหลาย ๆ Record ครับ
asp_access_multiple_insert1.asp
<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<form action="asp_access_multiple_insert2.asp" name="frmAdd" method="post">
Select Line :
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<%
Dim i , sel , line
For i = 1 To 50
If CInt(Request.QueryString("Line")) = i Then
sel = "selected"
Else
sel = ""
End IF
%>
<option value="<%=Request.ServerVariables("SCRIPT_NAME")%>?Line=<%=i%>" <%=sel%>><%=i%></option>
<%
Next
%>
</select>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="160"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="70"> <div align="center">Budget </div></th>
<th width="70"> <div align="center">Used </div></th>
</tr>
<%
line = Request.QueryString("line")
IF line = "" Then
line = 1
End IF
For i = 1 To line
%>
<tr>
<td><div align="center"><input type="text" name="txtCustomerID<%=i%>" size="5"></div></td>
<td><input type="text" name="txtName<%=i%>" size="20"></td>
<td><input type="text" name="txtEmail<%=i%>" size="20"></td>
<td><div align="center"><input type="text" name="txtCountryCode<%=i%>" size="2"></div></td>
<td align="right"><input type="text" name="txtBudget<%=i%>" size="5"></td>
<td align="right"><input type="text" name="txtUsed<%=i%>" size="5"></td>
</tr>
<%
Next
%>
</table>
<input type="submit" name="submit" value="submit">
<input type="hidden" name="hdnLine" value="<%=i-1%>">
</form>
</body>
</html>
asp_access_multiple_insert2.asp
<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<%
Dim Conn,strSQL,objExec,i
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/mydatabase.mdb"),"" , ""
For i = 1 To Request.Form("hdnLine")
If Trim(Request.Form("txtCustomerID" & i)) <> "" Then
strSQL = ""
strSQL = strSQL &"INSERT INTO customer "
strSQL = strSQL &"(CustomerID,Name,Email,CountryCode,Budget,Used) "
strSQL = strSQL &"VALUES "
strSQL = strSQL &"('"&Request.Form("txtCustomerID" & i)&"','"&Request.Form("txtName" & i)&"', '"&Request.Form("txtEmail" & i)&"' "
strSQL = strSQL &",'"&Request.Form("txtCountryCode" & i)&"','"&Request.Form("txtBudget" & i)&"', '"&Request.Form("txtUsed" & i)&"') "
Set objExec = Conn.Execute(strSQL)
End IF
Next
Response.write("Save completed. Click <a href='asp_access_multiple_insert3.asp'>here</a> to view.")
Conn.Close()
Set objExec = Nothing
Set Conn = Nothing
%>
</body>
</html>
asp_access_multiple_insert3.asp
<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<%
Dim Conn,strSQL,objRec
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/mydatabase.mdb"),"" , ""
strSQL = "SELECT * FROM customer "
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn, 1,3
%>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<%
While Not objRec.EOF
%>
<tr>
<td><div align="center"><%=objRec.Fields("CustomerID").Value%></div></td>
<td><%=objRec.Fields("Name").Value%></td>
<td><%=objRec.Fields("Email").Value%></td>
<td><div align="center"><%=objRec.Fields("CountryCode").Value%></div></td>
<td align="right"><%=objRec.Fields("Budget").Value%></td>
<td align="right"><%=objRec.Fields("Used").Value%></td>
</tr>
<%
objRec.MoveNext
Wend
%>
</table>
<%
objRec.Close()
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing
%>
</body>
</html>
Date :
2011-05-13 10:58:33
By :
webmaster
ขอบคุณก่อน
คือผมเขียนไปแล้วนะครับ
โดยใช้ java ควบคุมการแสดง textbox
var gFiles = 0;
function addFile(rq) {
var div = document.createElement('div');
div.setAttribute('id', 'file-' + gFiles);
div.innerHTML = '<input type="text" name="Rname[]" style="margin-left:157px; WIDTH: 430px;"><span onclick="removeFile(\'file-' + gFiles + '\')" style="cursor:pointer;"><img src="/Intranet_test/hr/img/icon_delete.gif" /></span>';
gFiles++;
}
function removeFile(aId) {
var obj = document.getElementById(aId);
obj.parentNode.removeChild(obj);
}
Date :
2011-05-13 11:02:18
By :
paisarn
Load balance : Server 05