使用Access 2002和VB从Listbox值进行查询(Visual Studio 2005) [英] Query from Listbox value using Access 2002 and VB (Visual Studio 2005)

查看:75
本文介绍了使用Access 2002和VB从Listbox值进行查询(Visual Studio 2005)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。这里的第一篇文章,如果它不是最好格式化的帖子,我提前道歉。我正在处理一个表单,该表单有一个绑定到访问表(名为CustomerInfo)的列表框(名为LstCustID)。我还有一个datagrid(名为DgvWOList),我想在其中将查询结果显示到它所绑定的表中(名为WorkOrder)。


我的问题是:我希望能够从列表框中选择客户并进行查询运行,该查询运行将拉出绑定到列表框的表的CustID(主)列的值,但仍显示客户名称列。该值是一个整数,此时我将其设置为名为CustC的公共变量。所以...我在我的查询中尝试了以下代码,但无济于事......此时我对如何设置它感到迷茫。


SQL:


SELECT [完成日期工作],[客户ID],[提供服务],[工单ID]

来自WorkOrder

WHERE ([客户ID] =表格!FrmWOList!CustC)

ORDER BY [完成日期工作]


它突破了WHERE部分,我认为它是因为CustC不是一个控制,而是一个变量。我只是不确定如何从变量中进行查询。我想我需要从我的查询中绑定到列表框的表中提取CustID而不是变量,但我也不确定如何去做。任何帮助将不胜感激!

Hi. First post here, so I apologize ahead of time if it isn''t the best-formatted post. I am working on a form that has a listbox (named LstCustID) that is bound to an access table (named CustomerInfo). I also have a datagrid (named DgvWOList) in which I want to display the results of my query into the table it is bound to (named WorkOrder).

My problem is this: I want to be able to select a customer from the listbox and have a query run that pulls the value of the CustID (primary) column of the table bound to the listbox, but still show the customer name column. The value is an integer, and at this point i have it set to be a public variable named CustC. So...I tried the following code in my query, but to no avail...and I am lost at this point on how to set it.

SQL:

SELECT [Date Work Completed], [Customer ID], [Services Offered], [Work Order ID]
FROM WorkOrder
WHERE ([Customer ID] = Forms ! FrmWOList ! CustC)
ORDER BY [Date Work Completed]

It breaks in the WHERE portion, and I think it is due to CustC not being a control, but rather a variable. I''m just not sure how to make the query work from a variable. I am thinking I will need to pull the CustID from the table bound to the listbox in my query rather than a variable, but I am also unsure as to how to go about doing that. Any help would be greatly appreciated!

推荐答案

Afterudate在您的表单上设置一个文本框=您的变量,然后将您的查询指向那个而不是很困惑,你做什么让我知道,如果这有帮助哦,当然,如果你让它工作只是将丑陋的TextBox设置为可见只要您设置列表框的更新后的变量就可以工作但是一个简单的问题是你只是试图将查询限制为ID =在列表框中选择的ID的记录/记录,因为在这种情况下忘记变量并只设置查询以查看列表框或Null
Afterudate set a text box on your form = your variable and then point your query to that instead little confuzzled as to what your doing let me know if that helps oh and of course if you get it working just set that ugly TextBox to visible No should work as long as your seting the variable afterupdate of the list box but a quick question are you just trying to limit the query to the record/records where the ID = the ID selected in the listbox because inthat case forget the variable and just set your query to look at the listbox or Null


我试图获取查询只执行列表框中选择的内容。不过,我不确定如何做到这一点。如果我可以跳过变量,那就更好了。


请注意,列表框会显示CustomerName。它所绑定的表的列,但我希望查询运行CustomerID;柱。我有可能吗?
I am trying to get the query to only do what is selected in the listbox. I am unsure how to get it to do that, though. If I can skip the variable, so much the better.

Please note that the listbox displays the "CustomerName" column of the table it is bound to, but I want the query to run off of the "CustomerID" column. I this possible?


好的..所以我设置了我的列表框控件的值参数来处理我想要的列。我的变量正确地拉取值(用msg框测试)。那么..如果我在更新后将文本框设置为具有该值的文本,我可以将查询设置为使用文本框的文本,对吧?


如果是这样的话,我该如何调整SQL?我仍然收到解析错误。
Okay..so I set the value parameters of my listbox control to work on the column I wanted it to. My variable pulls the value properly (tested with a msg box). So..if I set the text box to have the text of that value after update, I can set the query to use the text box''s text, right?

If so, how would I adjust the SQL? I''m still getting a parsing error.


这篇关于使用Access 2002和VB从Listbox值进行查询(Visual Studio 2005)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆