【问题标题】:Sql query added to title?Sql 查询添加到标题?
【发布时间】: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");
                    }

【问题讨论】:

    标签: sql add title updates


    【解决方案1】:

    这是因为您正在设置 rextonToolStripMenuItem.Text to rextonToolStripMenuItem.Text + " " + result 附加到以前的文本

    要么将文本设置为空白,然后再次设置,要么直接说

    rextonToolStripMenuItem.Text = "rexton " + result
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多