用ASP編緝資料庫記錄

來源:互聯網
上載者:User
資料|資料庫 <%' 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)};DBQ=" & Server.Mappath
("./db_scratch.mdb") & ";"
' We don't use these, but we could if we neeeded to.
'Const DB_USERNAME = "username"
'Const DB_PASSWORD = "password"

'Now we 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
' You can find these in the adovbs.inc file
' Do a search for it and it should turn up somewhere on the server
' If you can't find it you can download our copy from here:
' http://www.asp101.com/samples/download/adovbs.inc
' It may not be the most recent copy so use it at 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 this 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 = 15 ' Cuts down on 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(Day(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 you have something to look at 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 While 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



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。