C# 将列的值添加到另一列

C# 将列的值添加到另一列,c#,sql,C#,Sql,我在sql中有一列名为hours,所以当我通过c visual studio在其中输入值时,我需要在windows窗体中显示总小时数 private void button6_Click(object sender, EventArgs e) { DateTime date1; DateTime date2; if (DateTime.TryParse(textBox7.Text, out date1) && DateTi

我在sql中有一列名为hours,所以当我通过c visual studio在其中输入值时,我需要在windows窗体中显示总小时数

 private void button6_Click(object sender, EventArgs e)
    {
        DateTime date1;
        DateTime date2;
        if (DateTime.TryParse(textBox7.Text, out date1) && DateTime.TryParse(textBox8.Text, out date2))
            textBox6.Text = (date2 - date1).ToString();
        else
            textBox6.Text = "Invalid format";
    }

你的问题不清楚。请尝试添加更多详细信息。您可以发布您到目前为止所做的工作吗..sql在您的代码中的位置?代码与您发布的问题无关。我需要显示在windows窗体上
private void button6_Click(object sender, EventArgs e)
{
Sqlconnection con=new SqlConnection(strcon);
con.Open();
SqlCommand cmd=new SqlCommand("SELECT SUM(column_name)as TotalHours FROM   table_name",con);
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
Label1.Text = dr[0].toString();
}
}