Solved

Update 2 tables at the same time

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now