Editing database records with ASP

Source: Internet
Author: User
Tags date definition constant constant definition
Data | Database <% ' defining some constants to make my life easier! (Same as Sample 1 & 2)
' Begin Constant Definition

' DB Configuration Constants
' Fake const So we can use the MapPath to make it relative.
' After this, strictly used as if it were a Const.
Dim db_connectionstring
db_connectionstring = "Driver={microsoft Access DRIVER (*.mdb)};D bq=" & Server.MapPath
("./db_scratch.mdb") & ";"
' We don ' t use this, but we could if we neeeded to.
' Const db_username = ' USERNAME '
' Const Db_password = ' PASSWORD '

' Now we are override the above settings to use our SQL Server.
' Delete the following line to use the sample Access DB.
db_connectionstring = Application ("sqlconnstring") & "Uid=" & Application ("Sqlusername")
& "; Pwd= "& Application (" SQLPassword ") &"; "

' ADODB Constants
' Can find this in the Adovbs.inc file
' Do a search for it and it should turn up somewhere on the server
' If can ' t find it for you can download we copy from here:
' Http://www.asp101.com/samples/download/adovbs.inc
' It may is ' the most recent copy so use it in your own risk.
%>
<!--#INCLUDE file= "Adovbs.inc"-->
<%
' End Constant Definition
%>

<%
Dim I ' Standard looping var
Dim irecordtoupdate ' Id of deleted record

' We ' re going to keep the as simple as We can.
' 1. Create a Recordset object
' 2 Connect the Recordset to the table
' 3. Find the record to update
' 4. Update the Record
' 5. Update the table
' 6. Close the Recordset

' Step 1:
Dim objRecordSet
Set objRecordSet = Server.CreateObject ("ADODB. Recordset ")

' Step 2:
' The syntax for the ' Open command is
' Recordset. Open Source, ActiveConnection, CursorType, LockType, Options
Objrecordset.open "Scratch", db_connectionstring, adOpenKeyset, adLockPessimistic, adCmdTable

Objrecordset.cachesize = "Cuts Down" round trips to our SQL Server

' Step 3:
Irecordtoupdate = CLng (Request.QueryString ("id"))

If irecordtoupdate <> 0 Then
If not objrecordset.eof Then
Objrecordset.movefirst
Do Until objrecordset.fields ("id") = irecordtoupdate
Objrecordset.movenext
Loop

' Step 4:
' Only update if they ' ve told us to, o/w we never run this

' String/text Data Type
Objrecordset.fields ("Text_field") = CStr (WeekdayName Weekday (Date ()))

' Integer Data Type
Objrecordset.fields ("Integer_field") = CInt (now ())

' Date/time Data Type
Objrecordset.fields ("Date_time_field") = Now ()

' Step 5:
' Only update if they ' ve told us to, o/w we never run this
Objrecordset.update
End If
End If


' Show Table
' Feel free to skip this area. (Ignore the man behind the curtain!)
' I ' m just showing the RS so your have something to look in when
' You view the sample.

Response.Write "<table border=" "1" "Cellspacing=" "2" "cellpadding=" "2" ">" & vbCrLf
Response.Write VbTab & "<TR>" & VbCrLf
Response.Write VbTab & VbTab & "<TD>id</TD>" & VbCrLf
Response.Write VbTab & VbTab & "<TD>text_field</TD>" & VbCrLf
Response.Write VbTab & VbTab & "<TD>integer_field</TD>" & VbCrLf
Response.Write VbTab & VbTab & "<TD>date_time_field</TD>" & VbCrLf
Response.Write VbTab & "</TR>" & VbCrLf
If not objrecordset.eof Then
Objrecordset.movefirst
' Show data
Do as not objrecordset.eof
Response.Write VbTab & "<TR>" & VbCrLf
For I = 0 to Objrecordset.fields.count-1
Response.Write VbTab & VbTab & "<td><a href=" "Db_update.asp?id=" &
Objrecordset.fields ("id") & "" > "& Objrecordset.fields (I) &" </TD> "& VbCrLf
Next
Response.Write VbTab & "</TR>" & VbCrLf
Objrecordset.movenext
Loop
End If
Response.Write "</TABLE>" & VbCrLf



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.