0

My mysql query in ASP.NET is not running. I have printed out string session so i know i have the value for it and connection string is working in all other methods so i know the issue is not there. Running the command manually in PHPMyadmin works fine. Another method which looks the same, only with select cmd works.

public IActionResult DeleteProfile()
    {
        string session = HttpContext.Session.GetString("session"); /* gets value (customerid) for user session */

        MySqlConnection conn = new MySqlConnection(connectionString);
        try
        {

            conn.Open();
            string cmdtxt = "UPDATE customer SET active = '0' WHERE customerid = @session";


            MySqlCommand cmd = new MySqlCommand(cmdtxt, conn);

            /**************** SQL PARAMETER ********///

            MySqlParameter parameter = new MySqlParameter();
            cmd.Parameters.AddWithValue("@session", session);

            /**************** SQL PARAMETER ********///


        }
        catch (Exception ex)
        {
            ViewBag.error = "Connection Error!\n" + ex.Message;


        }
        finally
        {

            conn.Close();
            ViewBag.error = "Account deleted";
            HttpContext.Session.Remove("session");
        }                

        return View("../Account/Index");
    }
1
  • where your cmd.ExecuteNonQuery(); statement ? Commented Mar 7, 2019 at 11:02

1 Answer 1

4

You're correctly instantiating the MySqlCommand and assigning the appropriate parameter, but then you're not doing anything with that command.

You need to execute the query, so it gets sent to the database server:

cmd.ExecuteNonQuery();
Sign up to request clarification or add additional context in comments.

1 Comment

Ops. I used MySqlDataAdapter on my insert commands in other parts of the code, is it more practial or other pros to use ExecuteNonQuery?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.