Solved

Update MDB record !!

Posted on 2001-07-09
8
404 Views
Last Modified: 2008-03-04
Hi !

Is the code below a corect UPDATE code, or can someone
correct it !!


<%

Set Conn = Server.CreateObject("ADODB.Connection")
DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; "
DSN = DSN & "DBQ=c:/passord/database.mdb"
Conn.Open DSN


strSQL = "UPDATE DISTINCTROW personer set "

strSQL = strSQL & "Fornavn = "'" & Request.Form("Fornavn") & "', "
strSQL = strSQL & "Etternavn = "'" & Request.Form("etternavn") & "', "
strSQL = strSQL & "Telefon = "'" & Request.Form("telefon") & "', "
strSQL = strSQL & "Fodtselsdato = "'" & Request.Form("fodt") & "', "
strSQL = strSQL & "Mail = "'" & Request.Form("mail") & "', "
strSQL = strSQL & "Adresse = "'" & Request.Form("Adresse") & "', "
strSQL = strSQL & "Postnummer = "'" & Request.Form("postnummer") & "', "
strSQL = strSQL & "Poststed = "'" & Request.Form("poststed") & "', "
strSQL = strSQL & "bruker = "'" & Request.Form("bruker") & "', "
strSQL = strSQL & "type = "'" & session ("abbonement") & "', "
strSQL = strSQL & "regdato = "'" & NOW & "', "
strSQL = strSQL & "Passord  = "'" & passord & "' where ID=Request.QueryString("ID")"
strSQL = strSQL & "values( "

strSQL = strSQL & "'" & Request.Form("Fornavn") & "', "
strSQL = strSQL & "'" & Request.Form("etternavn") & "', "
strSQL = strSQL & "'" & Request.Form("telefon") & "', "
strSQL = strSQL & "'" & Request.Form("fodt") & "', "
strSQL = strSQL & "'" & Request.Form("mail") & "', "
strSQL = strSQL & "'" & Request.Form("Adresse") & "', "
strSQL = strSQL & "'" & Request.Form("postnummer") & "', "
strSQL = strSQL & "'" & Request.Form("poststed") & "', "
strSQL = strSQL & "'" & Request.Form("bruker") & "', "
strSQL = strSQL & "'" & session ("abbonement") & "', "
strSQL = strSQL & "'" & NOW & "', "
strSQL = strSQL & "'" & passord & "')"

' SQL s?tning eksekveres
response.write strSQL
Conn.Execute(strSQL)

response.write rs("id")
response.write rs("fornavn")

' Luk databaseforbindelse
Conn.Close
Set Conn = Nothing
set faluring = Nothing
response.redirect ("profil.asp")





%>
0
Comment
Question by:MEW_TWO
8 Comments
 
LVL 3

Expert Comment

by:phuctran
ID: 6267167
Check the structure of your table:
1. if the field is string type then use
strSQL = strSQL & "Fornavn = '" & Replace(Request.Form("Fornavn"), "'", "''") & "', "
2. if the field is number then use
strSQL = strSQL & "Fornavn = " & Request.Form("Fornavn") & ", "
3. if the field is date then use
strSQL = strSQL & "Fornavn = #" & Now & "#, "

0
 
LVL 3

Expert Comment

by:phuctran
ID: 6267176
one more thing:
the syntax for updating is

update <tablename>
set
<column> = <new value>,
<column> = <new value>,
<column> = <new value>
where <boolean condition>

for example:
strSQL = "UPDATE personer set " & _
   "Fornavn = '" & Replace(Request.Form("Fornavn"), "'", "''") & "', " & _
   "Etternavn = '" & Replace(Request.Form("etternavn"), "'", "''") & "', " & _
   "where where ID=" & Request.Form("ID")

YOUR MISTAKES:
1. you use Request.Form and Request.QueryString at the same time.  Should use only one.
2. You have extra "double quotes" when you build the query.

0
 
LVL 3

Expert Comment

by:phuctran
ID: 6267235
always, copy and paste problem :-)

strSQL = "UPDATE personer set " & _
  "Fornavn = '" & Replace(Request.Form("Fornavn"), "'", "''") & "', " & _
  "Etternavn = '" & Replace(Request.Form("etternavn"), "'", "''") & "' " & _
  " where ID=" & Request.Form("ID")

NOTE: no comma before "where"

0
 
LVL 33

Accepted Solution

by:
hongjun earned 25 total points
ID: 6267345
Try this
I am not sure what is rs. It could be a recordset object but I do not see where it is declared so I commented it out. I added a response.buffer=true at the beginning of the code so that response.redirect will work reliably. I also changed the dbq value to \ instead of /. I include a replace function for all string fields. Changed the date and guard it with # instead of '.

<%
Response.Buffer = true

Set Conn = Server.CreateObject("ADODB.Connection")
DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; "
DSN = DSN & "DBQ=c:\passord\database.mdb"
Conn.Open DSN


strSQL = "UPDATE DISTINCTROW personer set "

strSQL = strSQL & "Fornavn = '" & replace(Request.Form("Fornavn"), "'", "''") & "', "
strSQL = strSQL & "Etternavn = '" & replace(Request.Form("etternavn"), "'", "''") & "', "
strSQL = strSQL & "Telefon = '" & replace(Request.Form("telefon"), "'", "''") & "', "
strSQL = strSQL & "Fodtselsdato = '" & replace(Request.Form("fodt"), "'", "''") & "', "
strSQL = strSQL & "Mail = '" & replace(Request.Form("mail"), "'", "''") & "', "
strSQL = strSQL & "Adresse = '" & replace(Request.Form("Adresse"), "'", "''") & "', "
strSQL = strSQL & "Postnummer = '" & replace(Request.Form("postnummer"), "'", "''") & "', "
strSQL = strSQL & "Poststed = '" & replace(Request.Form("poststed"), "'", "''") & "', "
strSQL = strSQL & "bruker = '" & replace(Request.Form("bruker"), "'", "''") & ', "
strSQL = strSQL & "type = '" & replace(session("abbonement"), "'", "''") & "', "
strSQL = strSQL & "regdato = #" & Now() & "#, "
strSQL = strSQL & "Passord  = '" & replace(passord, "'", "''") & "' where ID = " & Request.Form("ID")


' SQL s?tning eksekveres
response.write strSQL
Conn.Execute(strSQL)

'response.write rs("id")
'response.write rs("fornavn")

' Luk databaseforbindelse
Conn.Close
Set Conn = Nothing
set faluring = Nothing
response.redirect ("profil.asp")
%>
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 20

Expert Comment

by:Silvers5
ID: 6267811
as said.. correct your syntax.. values should be only in an insert statement.. also don't forget to set write permissions on the mdb if it's hosted on an ntfs partition
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6267819
Silvers5 is correct. That's why I removed the values from the sql string above.

hongjun
0
 

Author Comment

by:MEW_TWO
ID: 6268241
I've now changed my code, and this is how it look
when I finaly got it to work :

' Databaseforbindelse - husk at angive sti til din database
Set Conn = Server.CreateObject("ADODB.Connection")
DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; "
DSN = DSN & "DBQ=c:/passord/database.mdb"
Conn.Open DSN


strSQL = "UPDATE DISTINCTROW personer set "

strSQL = strSQL & "Fornavn = '" & replace(Request.Form("Fornavn"), "'", "''") & "', "
strSQL = strSQL & "Etternavn = '" & replace(Request.Form("etternavn"), "'", "''") & "', "
strSQL = strSQL & "Telefon = '" & replace(Request.Form("telefon"), "'", "''") & "', "
strSQL = strSQL & "Fodtselsdato = '" & replace(Request.Form("fodt"), "'", "''") & "', "
strSQL = strSQL & "Mail = '" & replace(Request.Form("mail"), "'", "''") & "', "
strSQL = strSQL & "Adresse = '" & replace(Request.Form("Adresse"), "'", "''") & "', "
strSQL = strSQL & "Postnummer = '" & replace(Request.Form("postnummer"), "'", "''") & "', "
strSQL = strSQL & "Poststed = '" & replace(Request.Form("poststed"), "'", "''") & "', "
strSQL = strSQL & "bruker = '" & replace(Request.Form("bruker"), "'", "''") & "', "
strSQL = strSQL & "type = '" & replace(session("abbonement"), "'", "''") & "', "
strSQL = strSQL & "regdato = '" & Now() & "', "
strSQL = strSQL & "Passord  = '" & replace(Request.Form("pass1"), "'", "''") & "' where ID ="& Request.QueryString("id")


' SQL execute
response.write strSQL
Conn.Execute(strSQL)

'response.write rs("id")
'response.write rs("fornavn")

' close sql
Conn.Close
Set Conn = Nothing
set faluring = Nothing
response.redirect ("profil.asp")

%>


But, one more thing, Why do the ....where ID ="& Request.QueryString("id")
Get "" when I've passed it from 'profil.asp' like this :
<form action="profil_rett.asp?id="&rs("ID") method="post">



0
 
LVL 33

Expert Comment

by:hongjun
ID: 6268586
Try this
<form action='<%response.write("profil_rett.asp?id=" & rs("ID"))%>' method="post">

hongjun
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now