Solved

Update 2 tables at the same time

Posted on 2014-01-03
3
465 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

803 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