1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:
| public static void fillDGV(DataGridView datagridview) { Connection.Connection con = Connection.Connection.getInstance(); SqlConnection sqlcon = con.Sqlcon; SqlCommand sqlcom = new SqlCommand("SELECT unterweisender,zeit,statusword,anzahlzuhörer " + "FROM tbleigenschaft", sqlcon); SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlcom; DataSet ds = new DataSet(); da.Fill(ds);
if (ds.Tables != null) { datagridview.DataSource = ds.Tables[0]; }
foreach (DataGridViewRow row in datagridview.Rows) { try { DateTime buffer;
if (row.Cells["zeit"].Value != null) { buffer = DateTime.Parse(row.Cells["zeit"].Value.ToString());
if (buffer.Date.ToString() == DateTime.Today.ToString()) { row.DefaultCellStyle.BackColor = System.Drawing.Color.Red; } else { row.DefaultCellStyle.BackColor = System.Drawing.Color.White; } } } catch (Exception e) { MessageBox.Show(e.Message, e.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } |