web 2.0

How to use ASP & SQL Server Edit/Update Multiple Rows Record

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

ASP & SQL Server (Edit/Update Multiple Record)

.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (2 votes, average: 1.00 out of 10)
Loading ... Loading ...

One Response to “How to use ASP & SQL Server Edit/Update Multiple Rows Record”

  1. 3somewhere…

Leave a Reply

You must be logged in to post a comment.