MySQL Forums
Forum List  »  MySQL for Visual Studio

Re: Getting a table to update when a certain option is selected
Posted by: Javier Rivera Zavala
Date: September 29, 2015 08:19AM

Hello James, thank you for posting in our forums.

I'm not sure If I understood your question correctly but I think the complete answer will depend on what technology are you using when you're referring to 'form' (my wild guess is ASP.NET or Windows Forms? I'dunno it could also refer to PHP or other).

So, basically you need to do 2 things.

1) Your update query will have to include a variable in which you will assign the value of 1 or 2 depending on what option you select.

2) Create some logic on your GUI to update the value of the variable created in step 1.

A) If you're using ASP.NET you may want to take a look at:
http://stackoverflow.com/questions/25163523/asp-net-c-sharp-passing-a-variable-into-mysql-query

Take into account some possible errors due to postbacks in between your actions with the GUI like in the following link (which the OP fixed by using a hidden field):
http://forums.asp.net/t/1883809.aspx?MySQL+Update+does+not+work+with+parameters+ASP+net+with+C+

B) If you're using Windows Forms you may want to take a look at (Look for the Update Data section):
http://www.c-sharpcorner.com/UploadFile/9582c9/insert-update-delete-display-data-in-mysql-using-C-Sharp/

C) And if you're using PHP:
http://stackoverflow.com/questions/5838709/using-variables-in-mysql-update-php-mysql

I'm mostly concerned that I didn't understand your question because of your last comment "The issue with this query is for each option, the second table doesn't update untill it has been entered twice??"

If you're using a control in your form (talking about web) to display the current status of Table2 you probably need to request it to be refreshed after the update operation has finished, best way to do so will be through an AJAX call.

If what you looked for is to update a different table depending on what option is selected I would construct the update statement in the same way I suggested doing with the variable.

pseudocode:

int tableSelected;

...

private ... Option_SelectedIndexChange(sender o, EventArgs e)
{
switch (e.Text)
{
case Reservation:
case Appointment:
tableSelected = 2;
case MMC:
case SYC Appointment:
case SYC Valuation Form:
tableSelected = 2;
default:
tableSelected = 0;
}
}
...

private String Updatequery ()
{
if (tableSelected < 1 )
throw new Exception("Error"); //Or something.
var TableName = tableSelected == 2 ? "Table2" : "Table1";
return "UPDATE " + TableName + " t"
"JOIN vehicle_collection.form " +
"ON t.TM_ID = vehicle_collection.form.TM_ID "+
"JOIN vehicle_collection.result "+
"ON vehicle_collection.form.Enquiry_Result_ID = vehicle_collection.result.Enquiry_Result_ID "+
"SET ind_summary.Total_Points = ind_summary.Total_Points + vehicle_collection.result.EnquiryValues, "+
"ind_summary.Target_Countdown = ind_summary.Target_Countdown - vehicle_collection.result.EnquiryValues "+
"WHERE t.TM_ID = \" 115 \"";
}


Hope this helps.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Getting a table to update when a certain option is selected
658
September 29, 2015 08:19AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.