<%@ LCID = 3081 %> <% Response.expires = 0 Response.expiresabsolute = Now() - 1 Response.addHeader "pragma", "no-cache" Response.addHeader "cache-control", "private" Response.addHeader "cache-control", "no-cache" Response.addHeader "cache-control", "no-store" Response.CacheControl = "no-cache" %> <% ewCurSec = 0 ' Initialise ' User levels Const ewAllowAdd = 1 Const ewAllowDelete = 2 Const ewAllowEdit = 4 Const ewAllowView = 8 Const ewAllowList = 8 Const ewAllowReport = 8 Const ewAllowSearch = 8 Const ewAllowAdmin = 16 %> <% ' Initialize common variables x_SITE_HEADING = Null: ox_SITE_HEADING = Null x_SITE_URL = Null: ox_SITE_URL = Null x_COMMENTS = Null: ox_COMMENTS = Null x_DFRECNUM = Null: ox_DFRECNUM = Null %> <% Response.Buffer = True ' Load key from QueryString bCopy = True x_DFRECNUM = Request.QueryString("DFRECNUM") If x_DFRECNUM = "" Or IsNull(x_DFRECNUM) Then bCopy = False End If ' Get action sAction = Request.Form("a_add") If (sAction = "" Or IsNull(sAction)) Then If bCopy Then sAction = "C" ' Copy record Else sAction = "I" ' Display blank record End If Else ' Get fields from form x_SITE_HEADING = Request.Form("x_SITE_HEADING") x_SITE_URL = Request.Form("x_SITE_URL") x_COMMENTS = Request.Form("x_COMMENTS") x_DFRECNUM = Request.Form("x_DFRECNUM") End If ' Open connection to the database Set conn = Server.CreateObject("ADODB.Connection") conn.Open xDb_Conn_Str Select Case sAction Case "C": ' Get a record to display If Not LoadData() Then ' Load Record based on key Session("ewmsg") = "No records found" conn.Close ' Close Connection Set conn = Nothing Response.Clear Response.Redirect "SITELINKlist.asp" End If Case "A": ' Add If AddData() Then ' Add New Record Session("ewmsg") = "Add New Record Successful" conn.Close ' Close Connection Set conn = Nothing Response.Clear Response.Redirect "SITELINKlist.asp" Else End If End Select %>

Add to TABLE: SITELINK

Back to List

<% If Session("ewmsg") <> "" Then %>

<%= Session("ewmsg") %>

<% Session("ewmsg") = "" ' Clear message End If %>
SITE HEADING ">
SITE URL ">
COMMENTS ">

<% conn.Close ' Close Connection Set conn = Nothing %> <% '------------------------------------------------------------------------------- ' Function LoadData ' - Load Data based on Key Value ' - Variables setup: field variables Function LoadData() Dim sSql, rs, sWhere, sGroupBy, sHaving, sOrderBy sSql = "SELECT * FROM [SITELINK]" sWhere = "" sGroupBy = "" sHaving = "" sOrderBy = "" If sWhere <> "" Then sWhere = sWhere & " AND " sWhere = sWhere & "([DFRECNUM] = " & AdjustSql(x_DFRECNUM) & ")" sSql = sSql & " WHERE " & sWhere If sGroupBy <> "" Then sSql = sSql & " GROUP BY " & sGroupBy End If If sHaving <> "" Then sSql = sSql & " HAVING " & sHaving End If If sOrderBy <> "" Then sSql = sSql & " ORDER BY " & sOrderBy End If Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sSql, conn If rs.Eof Then LoadData = False Else LoadData = True rs.MoveFirst ' Get the field contents x_SITE_HEADING = rs("SITE_HEADING") x_SITE_URL = rs("SITE_URL") x_COMMENTS = rs("COMMENTS") x_DFRECNUM = rs("DFRECNUM") End If rs.Close Set rs = Nothing End Function %> <% '------------------------------------------------------------------------------- ' Function AddData ' - Add Data ' - Variables used: field variables Function AddData() Dim sSql, rs, sWhere, sGroupBy, sHaving, sOrderBy Dim bCheckKey, sSqlChk, sWhereChk sSql = "SELECT * FROM [SITELINK]" sWhere = "" sGroupBy = "" sHaving = "" sOrderBy = "" ' Check for duplicate key bCheckKey = True sWhereChk = sWhere If x_DFRECNUM = "" Or IsNull(x_DFRECNUM) Then bCheckKey = False Else If sWhereChk <> "" Then sWhereChk = sWhereChk & " AND " sWhereChk = sWhereChk & "([DFRECNUM] = " & AdjustSql(x_DFRECNUM) & ")" End If If bCheckKey Then sSqlChk = sSql & " WHERE " & sWhereChk Set rsChk = conn.Execute(sSqlChk) If Not rsChk.Eof Then Session("ewmsg") = "Duplicate value for primary key" rsChk.Close Set rsChk = Nothing AddData = False Exit Function End If rsChk.Close Set rsChk = Nothing End If ' Add New Record If sWhere <> "" Then sWhere = sWhere & " AND " sWhere = sWhere & "(0 = 1)" sSql = sSql & " WHERE " & sWhere If sGroupBy <> "" Then sSql = sSql & " GROUP BY " & sGroupBy End If If sHaving <> "" Then sSql = sSql & " HAVING " & sHaving End If If sOrderBy <> "" Then sSql = sSql & " ORDER BY " & sOrderBy End If Set rs = Server.CreateObject("ADODB.Recordset") rs.CursorLocation = 3 rs.Open sSql, conn, 1, 2 rs.AddNew ' Field SITE_HEADING sTmp = Trim(x_SITE_HEADING) If Trim(sTmp) = "" Then sTmp = "" rs("SITE_HEADING") = sTmp ' Field SITE_URL sTmp = Trim(x_SITE_URL) If Trim(sTmp) = "" Then sTmp = "" rs("SITE_URL") = sTmp ' Field COMMENTS sTmp = Trim(x_COMMENTS) If Trim(sTmp) = "" Then sTmp = "" rs("COMMENTS") = sTmp rs.Update rs.Close Set rs = Nothing AddData = True End Function %>