2
我有一個數據網格,其中的時間值列如0:15,0:30,0:45,1:00。將字符串單元格值轉換爲秒
當row.Cells [2]字符串的值高於1:00,所以它的3600時,我想將背色變爲紅色。我想我需要將它轉換爲秒,然後檢查它是否高於searchValue。我設法檢查是否平等,但我不知道如何將其轉換爲秒,然後檢查它是否更高。
SqlDataAdapter asdf;
DataTable ss;
asdf = new SqlDataAdapter("SELECT Firma, Czas, Opis,ID FROM Rok2016 WHERE [email protected] AND [email protected]", con);
asdf.SelectCommand.Parameters.AddWithValue("@DT", monthCalendar1.SelectionRange.Start.Date);
asdf.SelectCommand.Parameters.AddWithValue("@Kto", label3.Text);
ss = new DataTable();
asdf.Fill(ss);
dataGridView1.DataSource = ss;
String searchValue = "3600";
foreach (DataGridViewRow row in dataGridView1.Rows)
if (row.Cells[2].Value.ToString().Equals(searchValue))
{
row.DefaultCellStyle.BackColor = Color.Red;
}
row.Cells [2] .Value.ToString()返回00:15 00:30等我輸入3600,因爲我認爲我必須以某種方式轉換00:15秒,然後比較它到小時 –
我已更新我的答案。這應該適合你。除了功能外,我還增加了一些安全功能。 –