Update a DB Record

Results 1 to 3 of 3

Thread: Update a DB Record

  1. #1
    Frustrated Guest

    Default Update a DB Record

    I am having some trouble using the suggested code from 4 guys regarding updating a database. The data form works well of course, but the database script I am trying to use here does not appear to execute past my "Got This Far" print statement.<BR><BR>I have left out the adCmdTable part of the rs.open statement in the 4 guys code and that allows the "Got This Far" to print.<BR><BR>If I include the adCmdTable, the print statement doesn&#039t execute.<BR><BR>The DSN points to an Access Database. I can tell the code is affecting the Access Database since Access can&#039t open it for a couple of minutes after I run the asp page.<BR><BR>The code I&#039m trying is below.<BR><BR>--------------------<BR><BR>&#060;%Option Explicit%&#062;<BR>&#060;HTML&#062;<BR>&#060;BODY& #062;<BR><BR><BR>&#060;%<BR>Const adOpenForwardOnly = 0<BR>Const AdLockOptimistic = 3<BR>Const adCmdTable = &H0002<BR><BR>Dim classRS, Connect<BR><BR><BR><BR>Set Connect = Server.CreateObject("ADODB.Connection")<BR>Connect .Open "dbtest"<BR><BR><BR><BR>Set classRS = Server.CreateObject("ADODB.Recordset")<BR>classRS. Open "SELECT * FROM Assignments", Connect,adOpenForwardOnly, adLockOptimistic<BR><BR>%&#062;<BR>&#060;%="GOT THIS FAR"%&#062;<BR>&#060;%<BR><BR><BR><BR>&#039Add a new record<BR><BR>classRS.AddNew<BR><BR>&#039Assign the info to the fields<BR><BR>classRS("class") = "larry"<BR>classRS("date") = "9/9/99"<BR>classRS("assignment") = "moe"<BR><BR>&#039Update the recordset<BR><BR>classRS.Update<BR><BR>&#039cleanu p<BR><BR>classRS.Close<BR>Set classRS = nothing<BR>Connect.close<BR>Set connect = nothing<BR>%&#062;<BR><BR>&#060;/BODY&#062;<BR>&#060;/HTML&#062;<BR>

  2. #2
    William Prugh Guest

    Default RE: Update a DB Record

    There is another way to go about the whole thing that me be easier to work through.<BR><BR>Set Connection = Server.CreateObject("ADODB.Connection")<BR>Connect ion.Open "DSN=dbtest"<BR><BR>SQLStmt = "SELECT * FROM Assignments;"<BR>SET RS = Connection.Execute(SQLStmt)<BR>SQLStmt = ""<BR><BR>&#039Now you can use the data in the recordset by reference<BR><BR>SQLStmt = "INSERT INTO TableName ([class], [date], [assignement]) VALUES "<BR>SQLStmt = SQLStmt & "(&#039" larry "&#039, #" 9/9/99"#, &#039" moe "&#039);"<BR> <BR>connection.Execute(SQLStmt)<BR> <BR>SQLStmt=""<BR>

  3. #3
    Frustrated Guest

    Default RE: Update a DB Record

    I tried using the code suggested by William Prugh. I had to change the syntax of the string that represented the Values to get it to compile with no errors. (apparently " were not needed).<BR><BR>However, I seem to run into a similar situation where my test print statement will not work past the Connection.execute statement and no changes are visible in the table.<BR><BR>Could I be up against something I&#039ve set up in NT that is causing the problem. The anonymous internet guest has read, write and execute permissions for the Database and read and execute permissions for the ASP file.<BR><BR>code here<BR>-------------<BR>&#060;%Option Explicit%&#062;<BR>&#060;HTML&#062;<BR>&#060;BODY& #062;<BR><BR><BR>&#060;%<BR><BR>Dim RS, Connection, SQLStmt<BR><BR><BR>Set Connection = Server.CreateObject("ADODB.Connection")<BR>Connect ion.Open "DSN=dbtest"<BR><BR>SQLStmt = "SELECT * FROM Assignments;"<BR>SET RS = Connection.Execute(SQLStmt)<BR>SQLStmt = ""<BR><BR>&#039Now you can use the data in the recordset by reference<BR><BR>SQLStmt = "INSERT INTO Assignments ([class], [date], [assignement]) VALUES "<BR><BR>SQLStmt = SQLStmt & "(&#039larry&#039, # 9/9/99#, &#039 moe &#039);"<BR><BR>Connetion.execute (SQLStmt)<BR>%&#062;<BR>&#060;%=sqlstmt%&#062;<BR> &#060;%<BR><BR>SQLStmt=""<BR><BR>RS.Close<BR>Se t RS = nothing<BR>Connection.close<BR>Set Connection = nothing<BR><BR>%&#062;<BR>&#060;/BODY&#062;<BR>&#060;/HTML&#062;<BR><BR><BR><BR>:(

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •