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