11 Ağustos 2007 Cumartesi

Using ADO to Update a Record in a Database

<% ID = 7 %>
<% NAME = "Joe Smoe" %>
<% MESSAGE = "This is another test" %>
<%
'declaring variables
'not neccesary but a good habit
Dim DataConn
Dim CmdUpdateRecord
Dim MYSQL
Set DataConn = Server.CreateObject("ADODB.Connection")
Set CmdUpdateRecord = Server.CreateObject("ADODB.Recordset")
'The line below shows how to use a system DSN instead of a DNS-LESS connection
'DataConn.Open "DSN=System_DSN_Name"
DataConn.Open "DBQ=" & Server.Mappath("../_database/database.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
MYSQL = "SELECT some_table.* FROM some_table WHERE (ID = " & ID & ")"
CmdUpdateRecord.Open MYSQL, DataConn, 1, 3
CmdUpdateRecord.Fields("NAME") = NAME
CmdUpdateRecord.Fields("MESSAGE") = MESSAGE
CmdUpdateRecord.Update
'closing objects and setting them to nothing
'not neccesary but a good habit
CmdUpdateRecord.Close
Set CmdUpdateRecord = Nothing
DataConn.Close
Set DataConn = Nothing
%>


0 Comments: