vb中的语句.净OLEDB / SQL查询



感谢您抽出宝贵的时间来查看我的问题!我是所有这一切的新手,我正在尽力解决解决方案,但我不断撞到砖墙。我正在尝试更新具有字符串值的MDB文件中的表格,在表的另一部分中满足了其他条件。我意识到呼吁琴弦是不好的做法!

我认为问题是SQL语句的位置吗?

感谢任何帮助,这是代码的一部分:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    'Declerations For Calling on
    Dim AnimalHouse As String
    AnimalHouse = "TestText"
    Dim AddressForAssingment As Integer
    AddressForAssingment = 1
    Dim IDCheckAssignment As Integer
    IDCheckAssignment = 1
    'Connection Information 
    Dim myConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ProjectDirectory.Text)
    Dim myCommand As New OleDbCommand("INSERT INTO IOInformation SET Description= '" & AnimalHouse & "' WHERE ID_number= '" & AddressForAssingment & "' AND ID_Check= '" & IDCheckAssignment & "'")
    myCommand.Connection = myConnection
    myConnection.Open()
    myCommand.ExecuteNonQuery()
    myConnection.Close()
End Sub

INSERTUPDATE是两个不同的命令。

您的查询现在是两者的混合,您想要的可能是:

UPDATE IOInformation SET Description = .... WHERE ...

这样。请查看参数化查询。

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
 'Declerations For Calling on
 Dim AnimalHouse As String
 AnimalHouse = "TestText"
 Dim AddressForAssingment As Integer
 AddressForAssingment = 1
 Dim IDCheckAssignment As Integer
 IDCheckAssignment = 1
 'Connection Information 
 Dim myConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ProjectDirectory.Text)
 Dim myCommand As New OleDbCommand("Update IOInformation SET [Description] = @animalHouse, WHERE ID_number = @addrForAssn AND ID_Check = @Id))
 myCommand.Parameters.AddWithValue("@animalHouse", AnimalHouse)
 myCommand.Parameters.AddWithValue("@addrForAssn", AddressForAssingment)
 myCommand.Parameters.AddWithValue("@Id", IDCheckAssignment)
 myCommand.Connection = myConnection
 myConnection.Open()
 myCommand.ExecuteNonQuery()
 myConnection.Close()

相关内容

  • 没有找到相关文章

最新更新