【发布时间】:2014-09-22 15:08:32
【问题描述】:
在 c# Windows 窗体中:
我在将 sql 查询结果作为文本添加到 ToolStripMenuItem.Text 时遇到问题。
ToolStripMenuItem 的标题应该是,公司 + 该公司的 sql 表中有多少订单,应该每 x 秒更新一次。
它每 5 秒将查询结果添加到文本中。我的问题是“添加”它。 前 5 秒后它看起来还可以“rexton 1”,但 5 秒后显示“rexton 1 1”等等......
这是我的代码:
//Rexton ordre klar til bestilling
SqlConnection con = new SqlConnection(@"Data Source=" + globalvariables.hosttxt + "," + globalvariables.porttxt + "\\SQLEXPRESS;Database=ha;Persist Security Info=false; UID='" + globalvariables.user + "' ; PWD='" + globalvariables.psw + "'");
SqlCommand command = con.CreateCommand();
command.CommandText = "SELECT COUNT(*) from bestillinger WHERE firma = @rexton and udlevering BETWEEN @date and @dateadd";
command.Parameters.AddWithValue("@bernafon", "Bernafon");
command.Parameters.AddWithValue("@gn_resound", "GN Resound");
command.Parameters.AddWithValue("@oticon", "Oticon");
command.Parameters.AddWithValue("@phonak", "Phonak");
command.Parameters.AddWithValue("@rexton", "Rexton");
command.Parameters.AddWithValue("@siemens", "Siemens");
command.Parameters.AddWithValue("@widex", "Widex");
con.Open();
command.ExecuteNonQuery();
string result = command.ExecuteScalar().ToString();
con.Close();
if (result != "0")
{
rextonToolStripMenuItem.Text = rextonToolStripMenuItem.Text + " " + result;
rextonToolStripMenuItem.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF1919");
}
【问题讨论】: