Title: no change in database after update query runned in c#
Tags: c#;mysql
Question: if I try to run my update query in c# I see no change in my database.
The weird thing is that I don't get an error message returned so I don't know what im doing wrong.
Hopefully one of you guys can spot what im doing wrong, thanks in advance
My Code:
public static void Builder()
Console.WriteLine("Opening SSH Connection...");
// Establishing ssh connection to server where MySql is hosted
using (var client = new SshClient("ssh_host", "ssh_username", "ssh_password"))
{
client.Connect();
if (client.IsConnected)
{
var portForwarded = new ForwardedPortLocal("151.154.11.224", 22, "151.154.11.224", 3306);
client.AddForwardedPort(portForwarded);
portForwarded.Start();
Console.WriteLine("SSH Connection Established!\n");
Console.WriteLine("Opening MySql Connection...");
// Establishing MySql connection to the database
using (MySqlConnection con = new MySqlConnection("SERVER=151.154.11.224;PORT=22;UID=DB_login;PASSWORD=DB_password;DATABASE=DB_tablename"))
{
Console.WriteLine("MySql Connection Established!\n");
// Opening the Connection
con.Open();
Console.WriteLine("Generating Query...");
// Making the Query
MySqlCommand command = new MySqlCommand("UPDATE catalog_product_entity_decimal SET value= 1114 WHERE value_id= 4063", con);
Console.WriteLine("Query Generated!");
}
client.Disconnect();
}
else
{
Console.WriteLine("Client cannot be reached...");
}
}
Comment: looks like you set the command, but you don't execute it

Comment: You don't show your database table column types, I assume from your code that they are numeric, in your where clause, if not, enclose the value in quotes.  Otherwise I don't see anything that stands out.

Here is the accepted answer: Assuming that your ssh and database credentials are correct, try adding command.ExecuteNonQuery(); to your query.
Why? :
You'r trying to run an UPDATE query but your not executing the query so (in your code) it will not do anything! :)
Add it like this:
Console.WriteLine("Generating Query...");
// Making the Query
MySqlCommand command = new MySqlCommand("UPDATE catalog_product_entity_decimal SET value= 1114 WHERE value_id= 4063", con);
command.ExecuteNonQuery();
Console.WriteLine("Query Generated!");

Here is another answer: Because you are not executing the fvalenzuela@example.net. What you have is just the command declaration as below
MySqlCommand command = new MySqlCommand("UPDATE catalog_product_entity_decimal SET..", con);
You also need to execute the query saying
command.ExecuteNonQuery();
See MySQL Connector Documentation for more information

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:05/16/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c#><mysql>', 'Title': 'no change in database after update query runned in c#', 'ViewCount': 64, 'id': 50373617, 'user_AboutMe': None, 'user_AccountId': 13585374.0, 'user_DisplayName': 'AsSEateR5000', 'user_Reputation': 35.0, 'user_Views': 0.0, 'user_id': 9800242.0}}