两列之间的MS访问查询 [英] MS access query between two columns
本文介绍了两列之间的MS访问查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi!
I have an access database with forms. I created a query that would filter records between range. The criteria will be coming from a textbox.
我尝试过:
以下是我的代码,但它给了我无价值记录。如何让这个查询读取文本框中的输入?
What I have tried:
below is my code but it is giving me a no value record. how would i make this query read the input from the textbox?
"SELECT TrainingType, Condensed FROM tblOTrainings WHERE LowerBound = " & .txtCJobLevel.Text & " BETWEEN LowerBound AND UpperBound"
推荐答案
使用参数化查询,并修复语法错误:
Use a parameterized query, and fix the syntax error:
Using connection As New OleDbConnection("...")
Using command As New OleDbCommand("SELECT TrainingType, Condensed FROM tblOTrainings WHERE @CJobLevel BETWEEN LowerBound AND UpperBound", connection)
command.Parameters.AddWithValue("@CJobLevel", txtCJobLevel.Text)
Dim table As New DataTable()
Dim da As New OleDbDataAdapter(command)
da.Fill(table)
...
End Using
End Using
您好Richard和Dave,只想更新您我的代码现在正在运行。 :)感谢您的回复!
Hi Richard and Dave, just want to update you that my code is working now. :) Thanks for your replies!
cn.Open()
cmd = cn.CreateCommand
cmd.CommandText = "SELECT Course, Condensed FROM tblOTrainings WHERE @CJobLevel BETWEEN LowerBound AND UpperBound"
cmd.Parameters.AddWithValue("@CJobLevel", .txtOJobLevel.Text)
Dim table As New DataTable("tblOTrainings")
Dim da As New OleDbDataAdapter(cmd)
da.Fill(table)
.dgOTraining.DataSource = table
这篇关于两列之间的MS访问查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文