Single Table Update in SQL Server:
Code:
update.asp:
Highlight
<%@ Language=VBScript %> <%option explicit%> <%if (request.querystring ("Updated")) = "True" then%>
The Record has been Updated
<%else%> <% Dim conn Dim rs Dim strSQL Dim sSQL Dim PrimaryKeyField PrimaryKeyField = request.querystring("PrimaryKeyField") strSQL = "exec sp_getTableNameData_byPrimaryKeyField " & PrimaryKeyField Set conn = ConnectSQLNT("DataBaseName", "ServerName") Set rs = server.createobject("adodb.recordset") rs.open strSQL, conn if rs.eof then rs.close: set rs = nothing conn.close: set conn = nothing response.redirect "list.asp?Error=True" end ifs %> <%do while NOT rs.eof%>
"> FieldName1:
size=10>
FieldName2:
size=10>
FieldName3:
size=10>
<% rs.moveNext loop rs.close: set rs = nothing conn.close: set conn = nothing %> <%end if%>
dbupdate.asp:
Highlight
<%@ Language=VBScript %> <%option explicit%> <% Dim cmd Dim conn Set conn = ConnectSQLNT("DataBaseName", "ServerName") Set cmd = Server.CreateObject("ADODB.Command") Set cmd.ActiveConnection = conn cmd.CommandType = adCmdStoredProc cmd.CommandText = "sp_UpdateTableName" cmd.Parameters.Append(cmd.CreateParameter("@PrimaryKeyField", adInteger, adParamInput, , Request.form("cboPrimaryKeyField"))) cmd.Parameters.Append(cmd.CreateParameter("@FieldName1", adInteger, adParamInput, , Request.form("cboFieldName1"))) cmd.Parameters.Append(cmd.CreateParameter("@FieldName2", adBoolean, adParamInput, , Request.form("cboFieldName2"))) cmd.Parameters.Append(cmd.CreateParameter("@FieldName3", adVarChar, adParamInput, 255, Request.form("cboFieldName3"))) cmd.execute Set cmd=nothing set Conn=nothing response.redirect "update.asp?Updated=True" %>
sp_getTableNameData_byPrimaryKeyField:
Highlight
CREATE PROCEDURE dbo.sp_getTableNameData_byPrimaryKeyField @PrimaryKeyField int AS SELECT tn.PrimaryKeyField, tn.FieldName1, tn.FieldName2, tn.FieldName3 FROM TableName tn WHERE PrimaryKeyField = @PrimaryKeyField
sp_UpdateTableName:
Highlight
CREATE PROCEDURE dbo.sp_UpdateTableName @PrimaryKeyField int, @FieldName1 int, @FieldName2 bit, @FieldName3 varchar(255) AS UPDATE TableName SET FieldName1 = @FieldName1, FieldName2 = @FieldName2, FieldName3 = @FieldName3 WHERE PrimaryKeyField = @PrimaryKeyField