无法使用vb.NET

时间:2017-07-23 17:50:15

标签: database vb.net

enter image description here

当我尝试更新我的数据库表时,我该怎么办?

为什么我收到此错误?

3 个答案:

答案 0 :(得分:0)

它是因为您的列中插入了不匹配的数据类型 将更新查询更改为此

update Hasil_Rml_Hallo_Bro SET Nilai_Error=" & Label3.text & " WHERE ID=" & label4.text

删除"'"撇号信

答案 1 :(得分:0)

始终使用参数

Dim query As String = "update Hasil_Rml_Hallo_Bro SET Nilai_Error= @Error WHERE ID=@Id"
Using connection As New OleDbConnection(connectionString)
    Using command As New OleDbCommand(query, connection)
        Dim errorParameter As New OleDbParameter With
        {
            .ParameterName = "@Error",
            .OleDbType = OleDbType.VarChar, // Or what is correct type in database
            .Value = Label3.text
        }
        Dim idParameter As New OleDbParameter With
        {
            .ParameterName = "@Id",
            .OleDbType = OleDbType.Integer, // Or what is correct type in database
            .Value = Integer.Parse(label4.text) // Convert to correct type if needed
        }
        command.Parameters.Add(errorParameter, idParameter)

        connection.Open()
        command.ExecuteNonQuery()
    End Using
End Using

请注意,您需要为参数添加正确的类型 - 与您使用的列类型相同。

答案 2 :(得分:0)

确保数据库中的列与您插入的列具有相同的数据类型。