none
当delete 数据库时拿到了这个error (Data type mismatch in criteria expression.) RRS feed

  • 问题

  • 我的delete function 得到了这个error (Data type mismatch in criteria expression.)可以帮忙看看是什么问题吗?

            If Me.DataGridView1.Rows.Count > 0 Then
                If Me.DataGridView1.SelectedRows.Count > 0 Then
                    Dim intcID As Integer = Me.DataGridView1.SelectedRows(0).Cells("CheckerID").Value
                    Select Case MsgBox("Did you sure you want to delete this data", MsgBoxStyle.YesNo, "Message Confirmation")
                        Case MsgBoxResult.Yes
                            MessageBox.Show("Your data have been deleted", "Message")
                        Case MsgBoxResult.No
                            MessageBox.Show("Your data have been keep", "Message")
                            Exit Sub
                    End Select
                    'open connection
                    If Not cnn.State = ConnectionState.Open Then
                        cnn.Open()
                    End If
                    'delete data
                    Dim cmd As New OleDb.OleDbCommand
                    cmd.Connection = cnn
                    cmd.CommandText = "DELETE FROM tbl_Info WHERE CheckerID=" & intcID
                    cmd.ExecuteNonQuery()
                    Me.RefreshData1()
                    'close connection
                    cnn.Close()
                End If
            End If

    这是我的数据库图

    2019年12月10日 6:29

全部回复

  • Hi christing,

    如果你的'CheckID'在数据库中的类型是 'Short Text',将 'CommandText ' 进行以下的修改:

          cmd.CommandText = "DELETE FROM tbl_Info WHERE CheckerID= " & "'" & intcID & "'"

    希望这对你有帮助。

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年12月10日 10:10
    版主
  • Hi christing,

    你的问题解决了吗?如果解决了话,请将正确的回答标记为答案,这将帮助其他遇到相同问题的人迅速找到答案。

    感谢你的支持。

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年12月31日 3:17
    版主
  • Hi christing,

    你的问题解决了吗?如果解决了的话,请将正确的回答标记为答案,或者你也可以将你的正确答案分享到论坛上,并标记为答案,这将帮助其他遇到相同问题的人迅速找到答案。

    感谢你的支持。

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年12月31日 3:20
    版主