gpt4 book ai didi

c# - 为什么我得到 : Fatal error encountered during command execution

转载 作者:行者123 更新时间:2023-11-29 11:56:50 25 4
gpt4 key购买 nike

每当我运行代码时,它都会返回这个特定的错误

MySqlException was unhandled by user code: Fatal error encountered during command execution

所指向的

long count = (long)cmd1Database.ExecuteScalar();

这里可能出现什么问题?我对 C# 完全陌生。任何帮助将不胜感激。

string constring = "Database=chtbuster;Data Source=localhost;User Id=root;Password='';";
string count1 = "SELECT COUNT(hostName) FROM chtbuster.processtable WHERE hostName = @machineName; ";
using (MySqlConnection conDataBase = new MySqlConnection(constring))
{
conDataBase.Open();

string insertprocess = "INSERT INTO chtbuster.processtable(processID,processFileName,processName,processPath,hostName) VALUES (@processID, @fileName, @exeFile, @filePath, @machineName);";
MySqlCommand cmd2Database = new MySqlCommand(insertprocess, conDataBase);

cmd2Database.Parameters.AddWithValue("@processID", processID);
cmd2Database.Parameters.AddWithValue("@filename", fileName);
cmd2Database.Parameters.AddWithValue("@exeFile", exeFile);
cmd2Database.Parameters.AddWithValue("@filePath", filePath);
cmd2Database.Parameters.AddWithValue("@machineName", machineName);
cmd2Database.ExecuteNonQuery();

//string checkname = "SELECT hostName FROM chtbuster.hostnametable WHERE (hostName=@machineName); ";
MySqlCommand cmd1Database = new MySqlCommand(count1, conDataBase);
long count = (long)cmd1Database.ExecuteScalar();
if (count == 1)
{
listBox1.Items.Add(new MyListBoxItem(Color.Gold, count + "st warning" + machineName + " has opened " + fileName + " from path " + filePath));
if(machineName == pc1.Text)
{
pc1.Image = Image.FromFile("../../firstwarning.png");
}
else if (machineName == pc2.Text)
{
pc2.Image = Image.FromFile("../../firstwarning.png");
}
else
{
pc3.Image = Image.FromFile("../../firstwarning.png");
}

}
else if (count == 2)
{
listBox1.Items.Add(new MyListBoxItem(Color.Orange, count + "nd warning" + machineName + " has opened " + fileName + " from path " + filePath));
if (machineName == pc1.Text)
{
pc1.Image = Image.FromFile("../../secondwarning.png");
}
else if (machineName == pc2.Text)
{
pc2.Image = Image.FromFile("../../secondwarning.png");
}
else
{
pc3.Image = Image.FromFile("../../secondwarning.png");
}
}
else if (count == 3)
{
listBox1.Items.Add(new MyListBoxItem(Color.Firebrick, count + "rd warning" + machineName + " has opened " + fileName + " from path " + filePath));
if (machineName == pc1.Text)
{
pc1.Image = Image.FromFile("../../thirdwarning.png");
}
else if (machineName == pc2.Text)
{
pc2.Image = Image.FromFile("../../thirdwarning.png");
}
else
{
pc3.Image = Image.FromFile("../../thirdwarning.png");
}
}
else { listBox1.Items.Add(new MyListBoxItem(Color.Gray, count + "th warning" + machineName + " has opened " + inputfile + " from path " + filePath)); }
conDataBase.Close();

最佳答案

您忘记添加cmd1Database命令所需的参数

 ----
string count1 = @"SELECT COUNT(hostName) FROM chtbuster.processtable
WHERE hostName = @machineName; ";
MySqlCommand cmd1Database = new MySqlCommand(count1, conDataBase);
cmd1Database.Parameters.AddWithValue("@machineName", machineName);
long count = (long)cmd1Database.ExecuteScalar();
----

关于c# - 为什么我得到 : Fatal error encountered during command execution,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33055756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com