Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Update MDB record !!

Posted on 2001-07-09
8
Medium Priority
?
423 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Accepted Solution

by:
hongjun earned 100 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
 
LVL 20

Expert Comment

by:Michel Sakr
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

782 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