如果我尝试在 C# 中运行我的更新查询,我发现我的数据库没有任何变化。
奇怪的是我没有收到返回的错误消息,所以我不知道我做错了什么。
希望你们中的一个能发现我做错了什么,在此先感谢
我的代码:
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("127.0.0.1", 22, "127.0.0.1", 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=127.0.0.1;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...");
}
}
}
最佳答案
因为您根本没有执行查询。你所拥有的只是如下的命令声明
MySqlCommand command = new MySqlCommand("UPDATE catalog_product_entity_decimal SET..", con);
您还需要执行查询
command.ExecuteNonQuery();
参见 MySQL Connector Documentation了解更多信息
关于c# - 在 C# 中运行更新查询后数据库没有变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50373617/