none
database not updated when using ExecuteNonQuery and SQL has special character RRS feed

  • Question

  • I have this in my code

    SqlConnection conn = new SqlConnection(appconfig.GetValue("connectionstring"));
    
    //Opening a connection
    conn.Open();
    
    SqlServer.ExecuteTransactionalQuery(conn, "update racermaster..[user] set is_active = 0 where user_account = '" + nTLogin + "'");
    
    //SqlServer.ExecuteTransactionalQuery(conn, "update racermaster..case_data set name = 'Moderate Sedation_AC 1' where case_id = 1055");
    
    conn.Close();

    But the database is not updated

    I know the connection works because I changed the update statement to update a different table (the commented out line)  and it worked.  The only difference I see is that for the one that doesn't work, I have to have [] around the table name otherwise it will fail because user is a keyword in sql.  Unfortunately, someone named a table that.

    Is there something I can do with the syntax of the update statement so it will actually update the User table?

    Thank You very much in advance

    Christine


    • Edited by Christine Edwards Tuesday, September 20, 2016 2:14 AM INCORRECT CODE
    • Moved by Oscar_Wu Wednesday, September 21, 2016 3:00 AM related to ADO.NET
    Tuesday, September 20, 2016 2:13 AM

All replies

  • Hi Christine,

    The SQL query look well.

    Did you check the [user] table have any Update Trigger to update is_active column?

    Thanks

    Tuesday, September 20, 2016 12:55 PM
  • Hi Christine Edwards,

    This forum is discussing Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor.

    Your issue may be related to ADO.NET development I will move this thread to corresponding forum for a professional answer.

    Sincerely,

    Oscar


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Wednesday, September 21, 2016 2:56 AM
  • Hi Christine,

    Are you sure that your user table has a row in it where user_account =  nTLogin?


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Wednesday, September 21, 2016 5:01 AM