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
Solved

Update 2 tables at the same time

Posted on 2014-01-03
3
467 Views
Last Modified: 2014-01-26
Hi everyone,

I like to update 2 tables in access at the same time. My script isn't working. I hope someone can help me out. Thank you in advance, Sander

<%
If (CStr(Request("MM_update")) = "form1") Then
  If (Not MM_abortEdit) Then
    ' execute the update
    Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_conn_leads_STRING
    MM_editCmd.CommandText = "UPDATE tbl_DAavgAmount SET fin_hist_01_totaal2014 = ?, fin_hist_01_2014 = ?, fin_hist_02_2014 = ?, fin_hist_03_2014 = ?, fin_hist_04_2014 = ?, fin_hist_05_2014 = ?, fin_hist_06_2014 = ?, fin_hist_07_2014 = ?, fin_hist_08_2014 = ?, fin_hist_09_2014 = ?, fin_hist_10_2014 = ?, fin_hist_11_2014 = ?, fin_hist_12_2014 = ? WHERE store_nummer = ?
	

    UPDATE tbl_DAavgPerc SET fin_hist_01_index2014perc = ?, fin_hist_01_2014perc = ?, fin_hist_02_2014perc = ?, fin_hist_03_2014perc = ?, fin_hist_04_2014perc = ?, fin_hist_05_2014perc = ?, fin_hist_06_2014perc = ?, fin_hist_07_2014perc = ?, fin_hist_08_2014perc = ?, fin_hist_09_2014perc = ?, fin_hist_10_2014perc = ?, fin_hist_11_2014perc = ?, fin_hist_12_2014perc = ? WHERE store_nummer = ?"  
	
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("fin_hist_01_totaal2014"), Request.Form("fin_hist_01_totaal2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("fin_hist_01_2014"), Request.Form("fin_hist_01_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 5, 1, -1, MM_IIF(Request.Form("fin_hist_02_2014"), Request.Form("fin_hist_02_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 5, 1, -1, MM_IIF(Request.Form("fin_hist_03_2014"), Request.Form("fin_hist_03_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 5, 1, -1, MM_IIF(Request.Form("fin_hist_04_2014"), Request.Form("fin_hist_04_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 5, 1, -1, MM_IIF(Request.Form("fin_hist_05_2014"), Request.Form("fin_hist_05_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 5, 1, -1, MM_IIF(Request.Form("fin_hist_06_2014"), Request.Form("fin_hist_06_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 5, 1, -1, MM_IIF(Request.Form("fin_hist_07_2014"), Request.Form("fin_hist_07_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 5, 1, -1, MM_IIF(Request.Form("fin_hist_08_2014"), Request.Form("fin_hist_08_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param10", 5, 1, -1, MM_IIF(Request.Form("fin_hist_09_2014"), Request.Form("fin_hist_09_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param11", 5, 1, -1, MM_IIF(Request.Form("fin_hist_10_2014"), Request.Form("fin_hist_10_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param12", 5, 1, -1, MM_IIF(Request.Form("fin_hist_11_2014"), Request.Form("fin_hist_11_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param13", 5, 1, -1, MM_IIF(Request.Form("fin_hist_12_2014"), Request.Form("fin_hist_12_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param14", 5, 1, -1, MM_IIF(Request.Form("MM_recordId"), Request.Form("MM_recordId"), null)) ' adDouble

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("fin_hist_01_index2014perc"), Request.Form("fin_hist_01_index2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("fin_hist_01_2014perc"), Request.Form("fin_hist_01_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 5, 1, -1, MM_IIF(Request.Form("fin_hist_02_2014perc"), Request.Form("fin_hist_02_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 5, 1, -1, MM_IIF(Request.Form("fin_hist_03_2014perc"), Request.Form("fin_hist_03_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 5, 1, -1, MM_IIF(Request.Form("fin_hist_04_2014perc"), Request.Form("fin_hist_04_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 5, 1, -1, MM_IIF(Request.Form("fin_hist_05_2014perc"), Request.Form("fin_hist_05_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 5, 1, -1, MM_IIF(Request.Form("fin_hist_06_2014perc"), Request.Form("fin_hist_06_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 5, 1, -1, MM_IIF(Request.Form("fin_hist_07_2014perc"), Request.Form("fin_hist_07_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 5, 1, -1, MM_IIF(Request.Form("fin_hist_08_2014perc"), Request.Form("fin_hist_08_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param10", 5, 1, -1, MM_IIF(Request.Form("fin_hist_09_2014perc"), Request.Form("fin_hist_09_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param11", 5, 1, -1, MM_IIF(Request.Form("fin_hist_10_2014perc"), Request.Form("fin_hist_10_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param12", 5, 1, -1, MM_IIF(Request.Form("fin_hist_11_2014perc"), Request.Form("fin_hist_11_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param13", 5, 1, -1, MM_IIF(Request.Form("fin_hist_12_2014perc"), Request.Form("fin_hist_12_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param14", 5, 1, -1, MM_IIF(Request.Form("MM_recordId"), Request.Form("MM_recordId"), null)) ' adDouble
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close
  End If
End If
%>

Open in new window

0
Comment
Question by:hanskoens
3 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 39753575
You cannot do it
same time
even if database supports distributed transactions.
I doubt it is necessary at all. It is enough to use a basic transaction which guarantees data consistency.

Even if you send insert/update command in the very same microsecond it won't guarantee that data will be written in the same moment. Disk transaction are serialized anyway.

When you are in transaction you could check whether any of updates is made correct record(s) and if not to reject transaction.

You could find initial information here

HTH

Ivo Stoykov
0
 
LVL 1

Accepted Solution

by:
Poseidaon earned 500 total points
ID: 39756570
Hi Sandler,

You can update / delete / insert many tables as u wish.

First of all i recomend you to write your own codes instead of Dreamweavers insert / update codes. ( i used to use them before but they are kinda pain ) let me show u an example ;

1- Redirect your update form to a new page.( to do this simply type the new address in your form action part  like :
     <form id="form1" name="form1" method="post" action="New_Page.asp">

2- Create New_Page.asp

you can either get form values to variable or directlly use in sql, i prefer getting them to a variable , then compare , then use in sql. to do this.

Name = Request.form("Name")
Surname = REquest.form("Surname")
Etc....

once you get the form values you can do other compare logics.


 
Dim SQL_Process
Dim SQL_Process_cmd
Dim SQL_Process_numRows
Set SQL_Process_cmd = Server.CreateObject ("ADODB.Command")
SQL_Process_cmd.ActiveConnection = MM_conn_leads_STRING



                           
SQL =  "Update User set Name = '"&Name&"', Surname = '"&Surname&"' etc.  "
                              
SQL_Process_cmd.CommandText = SQL
SQL_Process_cmd.Prepared = true

Set SQL_Process = SQL_Process_cmd.Execute

                           
SQL =  "Update User2 set Name = '"&Name&"', Surname = '"&Surname&"' etc.  "
                              
SQL_Process_cmd.CommandText = SQL
SQL_Process_cmd.Prepared = true

Set SQL_Process = SQL_Process_cmd.Execute

Response.redirect("Main_Page.asp")

Hope u got the logic

Please feel free to ask anyquestions if you need
0
 
LVL 2

Author Comment

by:hanskoens
ID: 39759235
Hi Poseidaon,

Thank you very much. This week iam gonna try and wil respond as soon as I did.

Greets Sander
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

860 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