/    Sign up×
Community /Pin to ProfileBookmark

Database Update

Can anyone tell me why the code below won’t work. I’ve tested to make sure that it’s pulling the right record when the recordset is opened. I’ve made sure that the value is being pulled over from the form. I’ve even made sure that it’s updating the recordset object, but for some reason the rsCore.Update isn’t actually updating the database. I know the database can be written to, because there is other code on the page that is adding a new record to another table in the same database.

Dim connDatabase
Dim rsCore
Dim strSelect
Dim strUID

strUID = Request.Form(“txtUID”)

Set connDatabase = Server.CreateObject(“ADODB.Connection”)
connDatabase.ConnectionString = “DSN=Database.dsn”

Set rsCore = Server.CreateObject(“ADODB.Recordset”)
strSelect = “SELECT * FROM tblCore WHERE UID = ” & strUID
rsCore.Open strSelect, connDatabase, , adLockPessimistic

If Request.Form(“txtFirstName”) <> “” then
rsCore(“FirstName”) = Request.Form(“txtFirstName”)
rsCore(“FirstName”) = Null
End If


Set rsCore = Nothing

Set connDatabase = Nothing

to post a comment

8 Comments(s)

Copy linkTweet thisAlerts:
@chazzyMay 15.2006 — you're getting a record set. you need to send an additional request to the DSN to update the data. i'm fairly confident that there is no resultset.Update method.

UPDATE tblCore SET FirstName= its value, ...

See also this article

Copy linkTweet thisAlerts:
@nbcrockettauthorMay 15.2006 — I've got books that use recordset.update and have also seen it used in tutorials on other sites. I'm also using the same code to update to a database in over a hundred other locations. Any ideas why it wouldn't work in this one location?
Copy linkTweet thisAlerts:
@ProWebMay 15.2006 — Agreed with Chazzy. Ive never seen Recordset.update used without the SQL statement.

Otherwise how would the SQL server know what you want to update?
Copy linkTweet thisAlerts:
@nbcrockettauthorMay 15.2006 — It's updating an Access database not a SQL Server.
Copy linkTweet thisAlerts:
@Master_ShakeMay 16.2006 — [CODE]strUID = Request.Form("txtUID")

strSelect = "SELECT * FROM tblCore WHERE UID = " & strUID[/CODE]

the top statement indicates to me that strUID is a string as you have identified it. so in the select statement you need to delimit it.

[CODE]strUID = Request.Form("txtUID")

strSelect = "SELECT * FROM tblCore WHERE UID = '" & strUID & "'"[/CODE]

now if this needs to be a number then you will have to change strUID to and integer or long integer whichever is appropriate, then you will not need the delimiters.

Master Shake
Copy linkTweet thisAlerts:
@nbcrockettauthorMay 16.2006 — The select statements not the problem. It's pulling the correct record and it is an integer so the delimiter isn't needed. I just need to know why the [B]rsCore.Update [/B] code isn't working. Any ideas?
Copy linkTweet thisAlerts:
@Master_ShakeMay 16.2006 — Only thing I could suggest is to play with cursortype and locktype, but I am a little confused how strUID has become an integer.

Master Shake
Copy linkTweet thisAlerts:
@nbcrockettauthorMay 16.2006 — I changed the cursortype to [B]adOpenDynamic[/B] and it started to work fine. This makes absolutely no sense to me. I've used this exact code in countless other locations and didn't have to use a cursortype. If anyone can explain why this one page would require it please feel free to enlighten me. Otherwise, thanks greatly for helping me out.

Just to clairify [B]strUID[/B] is getting it's value from [B]Request.Form("txtUID")[/B]. [B]Request.Form("txtUID")[/B] is a hidden value on the previous page that I control and already know is a number.


Help @nbcrockett spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ

legal: ({
terms: of use,
privacy: policy
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
recent_tips: (
tipper: @junehugh,
tipped: article
amount: 500 SATS,

tipper: @buildinteractive,
tipped: article
amount: 1000 SATS,

tipper: @farhadmalegam,
tipped: article
amount: 1000 SATS,