Solved

Update 2 tables at the same time

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

Suggested Solutions

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

713 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