Tips for sending a MySQL parameter

Hey there, I need some help with the trigger setup I have:

CREATE TRIGGER `update` AFTER UPDATE ON `table 1` 
FOR EACH ROW INSERT INTO table 2 (
Id,
Revision,
Purpose,
Change
)
VALUES
(
OLD.Id,
OLD.Revision,
OLD.Purpose,
@purpose_change  /* user variable */
);

$$ DELIMITER ;

I'm working with C# WebService, Ajax, and JavaScript. Below are my C# methods for update (currently not functioning correctly)

"UPDATE table 1 SET Revision=@revision, Purpose=@purpose, @purpose_change=@change WHERE (Id =@id)";

The issue arises as I am unsure about how to send @purpose_channge properly.

Here's my Web Method.

[WebMethod(EnableSession = true)]
public string UpdateAlert(int id, string revision, string purpose, string change, int op)
{
    string response = "An Error Has Occurred.";
    try
    {
        UpdateAlert ua = new UpdateAlert(id, revision, purpose, change);

        int resp = conn.UpdateAlerta(ua, op);

        if (resp > 0)
            response = "Success!.";
    }
    catch (Exception ex)
    {
        response = "An Error Has Occurred: " + ex.Message;
    }
    return response;
}

And here's my JavaScript function with AJAX call.

 $.ajax({
    type: "POST",            
    url: urlServer + "ws_alerts.asmx/ActualizarAlerta",                      
    data: '{' +
        '"id":' + id +
        ',"revision":"' + rev +
        '","purpose":"' + pur +           
        '","change":"' + change +
        '","op":' + op + '}',      
    dataType: "json",              
    contentType: "application/json",        
    timeout: 60000,       
    error: function (xhr) {  
        bootbox.alert("An error occurred while processing the request.");
    },
    success: function (data) {
        bootbox.alert(data.d);
    }
});

id, rev, change, etc. values are retrieved using $('#MyId').val()

The main problem lies in the Update query but I am uncertain how to correct it. Any suggestions on what needs to be done?

Answer №1

If you are using a MySQL user variable, it is necessary to execute a raw query before calling the UpdateAlerta() function.

SqlCommand cmd = new SqlCommand("set @purpose_change = 'Purpose change to 1';", conn);
cmd.ExecuteNonQuery();

Just a reminder (I recall seeing another relevant post here)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Flexbox Resizing Notification(?)

Recently, I've been utilizing flexbox in my layout design and it has been a game-changer. However, I am facing an issue that might be linked to my heavy use of AngularJS, particularly the ng-include feature. The specific problem arises when I incorpo ...

What is the best way to substitute unpredictable dynamic variables on-the-fly?

I am working with a .js file that contains a config structure similar to this: genGetLocations:{ data_url:'restaurants/{var1}/tables/{var2}, } This is just one example. Some configurations may have data_url with more than two dynamic variables. I ...

HighCharts velocity gauge inquiry

I recently integrated a highcharts speedometer with PHP and MYSQL on my website. Everything seemed to be working smoothly until I added the JavaScript code for the speedometer, causing it not to display. There are no error messages, just a blank screen whe ...

Sending reference variable from Angular input type=file

I am currently learning Angular and I have implemented a feature where a list of PDF files is displayed using an array called pdfs. In my template, these PDF files are parsed into "card" elements for better visualization. The issue arises when I attempt ...

A guide on verifying text obtained from an API endpoint using c#

I am currently developing an automation test that involves interacting with an endpoint URL 'https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1'. Upon accessing this endpoint, certain text is displayed. Can someone advise me on how I ...

symfony submit form without sending request

I'm trying to make a request without using a submit button, only by selecting an option. So far, I've attempted to achieve this using JavaScript but haven't had any success. Here's my form code: $form = $this->createFormBuilder() ...

jQuery functions failing to target dynamically generated elements

I've encountered an issue while attempting to implement my jQuery functions on dynamically created content using the .on API from jQuery. The main objective of the code is to display a specific set of options only when a user hovers over the ".feed_po ...

Tips for repairing a button using a JavaScript function in an HTML document

I am currently working on extracting titles from body text. To achieve this, I have created a button and linked my function to it. The issue I am facing is that when I click on the button, it disappears from its original position. I intend to keep it in pl ...

The $OnChange function fails to activate when passing an object by reference

Hi there, I've encountered a problem in my code that I'd like some help with. In my example, I have two components: Parent Component and Child Component. Both components share a field called rules. The Parent Component passes the rules field to ...

Verification of javascript for an unpredictable image generator script

When running the W3C Validation tool, an error is returned stating 'img not acceptable here.' Any suggestions on how to resolve this issue? <script type="text/javascript" language="JavaScript"> NumberOfImagesToRotate = 9; FirstPart = &ap ...

PHP encountered a problem while trying to insert data into a MySQL database

Upon execution of my code, the following error is displayed: An SQL syntax error occurred. Please refer to the MySQL server manual for guidance on correct syntax. The error specifically points to the line near '16:45:40, 2012-12-18 16:45:40, Renovate ...

Automatically switch to the designated tab depending on the URL

Is it possible to automatically activate a specific tab based on the URL structure if my tabs are configured in this way? I am looking for a solution where a link on www.example1.com/notabs.html will redirect to www.example2.com/tabs.html This particular ...

Creating a polyBezier or polyCurve with Canvas HTML: a step-by-step guide

Looking to connect several points with a curve rather than just a straight line. I attempted using the lineTo() and bezierCurveTo() methods to draw the points. Is there anyone who can assist me in solving this dilemma? Perhaps there is a different approac ...

Issue with AngularJS filter not functioning properly

I have a specific situation where I am using an ng-repeat directive in the following manner: {"ng-repeat" => "city in cities() | filter: search"} In this context, each city object is structured like so: { attributes: {name: 'Boston'} } Furt ...

The Ajax response is coming back with a null value, but upon inspecting the network response

I'm facing a strange issue where one specific value from an ajax json response is showing up as an empty string, while all other values are appearing correctly. An unusual aspect of this problem is that the network panel displays the correct value in ...

Typescript enhances React Native's Pressable component with a pressed property

I'm currently diving into the world of typescript with React, and I've encountered an issue where I can't utilize the pressed prop from Pressable in a React Native app while using typescript. To work around this, I am leveraging styled comp ...

Why won't my div tag show conditionally with AngularJS ng-show?

I'm having trouble displaying a div tag on a form based on the boolean flag specified in ng-show. Unfortunately, the div is not showing up at all. Here's what I've tried so far without success. Any assistance would be greatly appreciated! F ...

Creating a button that allows updates without refreshing the page can be achieved by implementing

Here are the items I have: <table> <tr> <th> id </th> <th> name </th> <th> update </th> </tr> <tr> ...

Encountering an error with my electron application built using create-react-app

While I'm working on my project, my electron window is showing this error message. TypeError: fs.existsSync is not a function getElectronPath ../node_modules/electron/index.js:7 4 | var pathFile = path.join(__dirname, 'path.txt') 5 | ...

Disable the button until all input fields contain text in ASP

Curious if anyone knows how to disable a button until all text boxes have input in ASP.NET and C#. Here is an image showing the scenario I'm referring to - wanting to gray out the commit button. Thanks, Chris! ...