将查询结果添加到标签字符串
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}";
我有一个标签,我希望显示标准消息"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}";