Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update MDB record !!

Posted on 2001-07-09
8
Medium Priority
?
421 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

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 informatio…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

704 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