如果药物已经过期,我已经更改了datagridview中行的背景颜色?
con.Open()
Dim query As String
query = "Select product_code,drug_name,quantity,expiration_date from medicine where expiration_date"
command = New MySqlCommand(query, con)
readers = command.ExecuteReader
Dim count As Integer
count = 0
While readers.Read
count = count + 1
End While
con.Close()
If count = 0 Then
MsgBox("no expiration")
Else
Dim SQL As String = ""
Dim da As MySqlDataAdapter = Nothing
Dim dt As New DataTable
SQL = "Select product_code,drug_name,quantity,expiration_date from medicine where expiration_date"
command = New MySqlCommand(SQL, con)
End If
好的拳头你需要用这种方式加载de grid与数据库数据:
con.Open()
Dim query As String
Dim da As new MySqlDataAdapter
Dim dt As New DataTable
query = "Select product_code,drug_name,quantity,expiration_date from medicine where expiration_date is not null"
command = New MySqlCommand(query, con)
da.SelectCommand = cm
da.Fill(dt)
dgv1.datasource = dt
然后你必须在cellformating事件中设置颜色:
Private Sub dgv1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles dgv1.CellFormatting
If dgv1.Rows(e.RowIndex).Cells("expiration_date").Value < now Then
dgv1.Rows(e.RowIndex).cells("expiration_date").Style.BackColor = Color.Red
End If
我不明白你要做什么或者你将如何加载网格。任何改变列颜色的方法都是:
dgv1.Columns("columnsName").DefaultCellStyle.BackColor = Color.Red