[英]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.