将列的值添加到另一列
本文关键字:一列 添加 | 更新日期: 2023-09-27 18:08:36
我在sql
中有一列命名为hours
,所以当我通过c# visual studio输入它的值时,我需要total hours
,我需要在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";
}
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();
}
}