Solved

Update MDB record !!

Posted on 2001-07-09
8
418 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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