How to use ASP & SQL Server Edit/Update Multiple Rows Record This is tutorial asp developers how to using ASP edit/update multiple record on SQL Server table.
ShotDev Focus:
- ASP & SQL Server edit/update multiple record.
Example
asp_sqlserver_edit_multiple.asp
<% Option Explicit %> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <% Dim Conn,strSQL,objRec,objExec,i Set Conn = Server.Createobject("ADODB.Connection") Conn.Open "Driver={SQL Server};Server=localhost;Database=mydatabase;UID=sa;PWD=;" '*** Update Condition ***' If Request.QueryString("Action") = "Save" Then ForĀ i = 1 To Request.Form("hdnLine") strSQL = "UPDATE customer SET " strSQL = strSQL &"CustomerID = '"&Request.Form("txtCustomerID" & i)&"' " strSQL = strSQL &",Name = '"&Request.Form("txtName" & i)&"' " strSQL = strSQL &",Email = '"&Request.Form("txtEmail" & i)&"' " strSQL = strSQL &",CountryCode = '"&Request.Form("txtCountryCode" & i)&"' " strSQL = strSQL &",Budget = '"&Request.Form("txtBudget" & i)&"' " strSQL = strSQL &",Used = '"&Request.Form("txtUsed" & i)&"' " strSQL = strSQL &"WHERE CustomerID = '"&Request.Form("hdnCustomerID" & i)&"' " Set objExec = Conn.Execute(strSQL) Next End IF strSQL = "SELECT * FROM customerĀ " Set objRec = Server.CreateObject("ADODB.Recordset") objRec.Open strSQL, Conn, 1,3 %> <form name="frmMain" method="post" action="asp_sqlserver_edit_multiple.asp?Action=Save"> <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> <% i = 0 While Not objRec.EOF i = i + 1 %> <tr> <td><div align="center"> <input type="hidden" name="hdnCustomerID<%=i%>" size="5" value="<%=objRec.Fields("CustomerID").Value%>"> <input type="text" name="txtCustomerID<%=i%>" size="5" value="<%=objRec.Fields("CustomerID").Value%>"> </div></td> <td><input type="text" name="txtName<%=i%>" size="20" value="<%=objRec.Fields("Name").Value%>"></td> <td><input type="text" name="txtEmail<%=i%>" size="20" value="<%=objRec.Fields("Email").Value%>"></td> <td><div align="center"><input type="text" name="txtCountryCode<%=i%>" size="2" value="<%=objRec.Fields("CountryCode").Value%>"></div></td> <td align="right"><input type="text" name="txtBudget<%=i%>" size="5" value="<%=objRec.Fields("Budget").Value%>"></td> <td align="right"><input type="text" name="txtUsed<%=i%>" size="5" value="<%=objRec.Fields("Used").Value%>"></td> </tr> <% objRec.MoveNext Wend %> </table> <input type="submit" name="submit" value="submit"> <input type="hidden" name="hdnLine" value="<%=i%>"> </form> <% objRec.Close() Conn.Close() Set objRec = Nothing Set Conn = Nothing %> </body> </html>
Create a asp file and save to path root-path/myasp/
Run
http://localhost/myasp/asp_sqlserver_edit_multiple.asp
Screenshot
3somewhere…
…