For i As Integer = Me.DataGridView1.SelectedRows.Count - 1 To 0 Step -1
Dim due_date As Object
Dim calc As TimeSpan
due_date = DataGridView1.Rows(i).Cells(3).Value()
**error** ---->>>calc = Today.Subtract(due_date)<<<--------**error**
MessageBox.Show(calc.ToString)
Dim Query As String
Query = "delete from periodicals where student_id= '" & Me.DataGridView1.SelectedRows(i).Cells(0).Value.ToString() & "'"
COMMAND = New MySqlCommand(Query, MysqlConn)
SDA.SelectCommand = COMMAND
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
Me.DataGridView1.Rows.Remove(Me.DataGridView1.SelectedRows(i))
DataGridView1.DataSource = bSource
SDA.Update(dbDataSet)
我试图在datagridview中减去今天和截止日期,并将通过消息框显示。我对如何解决这个问题一无所知。建议
答案 0 :(得分:0)
&#34;模糊匹配&#34;错误可能是因为due_date被实例化为Object。减法函数不知道要从哪个数据类型中减去。
也许试试:
Dim due_date As DateTime
希望对你有用!
答案 1 :(得分:0)
Dim due As Date
Dim calc As TimeSpan
Dim d1 As Date
Try
MysqlConn.Open()
For i As Integer = Me.DataGridView1.SelectedRows.Count - 1 To 0 Step -1
d1 = Format(Now, "yyyy-MM-dd")
due = DataGridView1.Rows(i).Cells(3).Value()
calc = d1.Subtract(due)
Dim fine As Integer = calc.Days * 20
If MessageBox.Show("Your Penalty is:₱" & fine & "" + vbNewLine + " Do you want to remove this as paid ?", "Informed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Dim Query As String
Query = "delete from periodicals where student_id= '" & Me.DataGridView1.SelectedRows(i).Cells(0).Value.ToString() & "'"
COMMAND = New MySqlCommand(Query, MysqlConn)
SDA.SelectCommand = COMMAND
SDA.Fill(dbDataSet)
感谢您的建议,最终它按照我希望的方式运作。