我在hours
中有一个名为sql
的列,所以当我通过c#visual studio输入值时,我需要total hours
我需要在窗体中显示。
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";
}
答案 0 :(得分:0)
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();
}
}