VB 中的 WHERE 语句.NET OleDB/SQL 查询

编程入门 行业动态 更新时间:2024-10-20 06:34:53
本文介绍了VB 中的 WHERE 语句.NET OleDB/SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

感谢您花时间看我的问题!我对这一切都很陌生,我正在尽最大努力找出解决方案,但我一直在碰壁.我正在尝试使用字符串的值更新 MDB 文件中的表,其中表的另一部分满足其他条件.我意识到调用字符串是不好的做法!

Thanks for taking the time to look at my question! I am new to all this and I am trying my best to work out the solution but I keep hitting a brick wall. I'm trying to update a table in a MDB file with the value of a String, where other conditions are met in another part of the table. I realise calling on strings is bad practise!

我认为问题出在 SQL 语句的 WHERE 部分?

I think the problem is with the WHERE part of the SQL statement?

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

Appreciate any help, here is part of the code:

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

推荐答案

像这样.请查看 参数化查询.

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()

更多推荐

VB 中的 WHERE 语句.NET OleDB/SQL 查询

本文发布于:2023-10-25 13:59:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527157.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   VB   NET   SQL   OleDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!