繁体   English   中英

将查询结果添加到标签字符串

[英]Adding Query result to label string

我有一个标签,希望标准消息显示“ Today's Total:”,我如何将查询结果添加到标签上该字符串的末尾。

var sql = @" SELECT COUNT (RTFPressTableID) AS NumberOfTables
             FROM RTFPressTables
             WHERE PressCloseTime BETWEEN DATEADD(day, DATEDIFF(day, 0, @Date), '06:00:00') 
             AND  DATEADD(day,DATEDIFF(day, 0, @Date), '23:59:59') ";
using (SqlConnection conn = new SqlConnection("Data Source = ; Initial Catalog = ; Integrated Security = True"))
{
    conn.Open();
    using (SqlCommand command = new SqlCommand(sql, conn))
    {
        command.Parameters.Add("@Date", SqlDbType.DateTime);
        command.Parameters["@Date"].Value = dateTimePicker1.Value.Date;
        Int32 count = Convert.ToInt32(command.ExecuteScalar());                    

        if (count > 0)
        {                        
           todaysTotal.Text = Convert.ToString(count.ToString());
            if (count >= 100)
            {
                todaysTotal.BackColor = Color.LawnGreen;
            }
        }

        else
        {
            todaysTotal.Text = "Todays Total: 0";
        }
        conn.Close();

对于任何与我的问题相似的人,iakobski给我的答案是正确的解决方案。 改变中

 todaysTotal.Text = Convert.ToString(count.ToString()); 

  todaysTotal.Text = $"Today's Total: {count}";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM