Solved

Update MDB record !!

Posted on 2001-07-09
8
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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
 
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

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!

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

734 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