条件表达式中的数据类型不匹配vb2010编辑按钮

时间:2015-10-21 02:47:50

标签: vb.net

我收到了错误

  

条件表达式中的数据类型不匹配vb.net编辑按钮

当我点击我的vb2010项目上的编辑按钮时。添加和搜索按钮工作正常但不在编辑按钮上。 这是我的代码:

Private Sub BtnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEdit.Click
    Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=D:\pcInventory.accdb"
    myConnection = New OleDbConnection

    OpenStr = "Has Open Office"
    If TbPCnum.Text = "" Then
        MsgBox("Please select data.")
    Else

        myConnection.ConnectionString = connString
        myConnection.Open()
        Dim str As String
        str = "update [pctable] set [Person Incharge] = '" & TbPI.Text & "', [DeptSection] = '" & TbDS.Text & "', [Workgroup] = '" & TbWG.Text & "', [Network ID] = '" & TbNI.Text & "', [OS] = '" & TbOS.Text & "', [Processor] = '" & TbProcessor.Text & "', [MOBO] = '" & TbMB.Text & "', [Memory] = '" & TbRAM.Text & "', [HDD] = '" & TbHDD.Text & "', [Product Key] = '" & TbKey.Text & "', [MS Office] = '" & CbMS.SelectedValue & "', [Open Office] = '" & tbOO.Text & "', [Anti Virus] = '" & TbAV.Text & "', [Monitor] = '" & TbMonitor.Text & "', [Email Address] = '" & TbEadd.Text & "', [Date Purchased] = '" & TbDP.Text & "', [Machine Type] = '" & comboMT.SelectedValue & "', [Remarks] = '" & TbRM.Text & "', [Password] = '" & TbPW.Text & "'     Where [PCNumber] = '" & TbPCnum.Text & "'"
        Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
        Try
            cmd.ExecuteNonQuery()
            cmd.Dispose()
            myConnection.Close()
            TbPCnum.Clear()
            TbPI.Clear()
            TbDS.Clear()
            TbWG.Clear()
            TbNI.Clear()
            TbOS.Clear()
            TbProcessor.Clear()
            TbMB.Clear()
            TbRAM.Clear()
            TbHDD.Clear()
            TbKey.Clear()
            tbOO.Clear()
            TbAV.Clear()
            TbMonitor.Clear()
            TbEadd.Clear()
            TbDP.Clear()
            TbRM.Clear()
            TbPW.Clear()


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

我怀疑它可能是你的查询字符串。例如,您发送字符串/文本而不是int / number。

检查它并确保数据库列类型与您通过查询发送的数据相匹配。

如果发送int / numeric值,请删除单引号。