如何使用3个组合框作为过滤器从单个表中过滤数据? [英] How to filter data from a single table using 3 comboboxes as filters?

查看:54
本文介绍了如何使用3个组合框作为过滤器从单个表中过滤数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有这3个组合框我需要过滤我的查询,所以它只显示有关3个组合框的数据。



以此为例:



ID |动机|票务观察|价格($)|平民身份证|截止日期|

1 |加快|当道路说90mph |时,汽车的行驶速度为200英里每小时350 $ | 15441151 | 2018年5月4日|



现在想象一下,我想过滤动机(超速)和民用ID(15441151)和截止日期(5月4日) 2018)?



这怎么可能?

我每次使用1个以上过滤器时都会收到此错误:

Hello, I have this 3 comboboxes tht I need to filter my query so it only show's the data regarding the 3 combobox combined.

Take for example this:

ID | Motive | Ticket Observation | Price($) | Civilian ID | Due-Date |
1 | Speeding| The car was going at 200mph when the road says 90mph| 350$ | 15441151 | 4th May 2018|

Now imagine that I want to filter the "motive"(speeding) and the "civilian ID"(15441151) and the due date(4th May 2018)?

How can this be possible?
I'm getting this error everytime i use more then 1 filter:

Quote:

将字符串SELECT * FROM dv_principal where转换为Double类型无效。 '

The conversion of the string "SELECT * FROM dv_principal where" to type 'Double' is not valid. '





我的尝试:





What I have tried:

SELECT * FROM dv_principal where MOTIVE='" + cmbMotive.SelectedValue + "' AND CIV_ID='" + cmbCliente.SelectedValue + " AND DUE_DATE= '"+ dtpDueDate.SelectedText+"'"

推荐答案

)|平民身份证|截止日期|

1 |超速驾驶|当道路说90mph时,汽车行驶速度为200mph | 350
) | Civilian ID | Due-Date |
1 | Speeding| The car was going at 200mph when the road says 90mph| 350


| 15441151 | 2018年5月4日|



现在想象我想过滤动机(超速)和民用ID(15441151)和到期日(2018年5月4日)?



这怎么可能?

我每次我使用超过1个过滤器时都会出现此错误:

| 15441151 | 4th May 2018|

Now imagine that I want to filter the "motive"(speeding) and the "civilian ID"(15441151) and the due date(4th May 2018)?

How can this be possible?
I'm getting this error everytime i use more then 1 filter:
Quote:

字符串转换SELECT *来自dv_principal,其中输入'Double'无效。'

The conversion of the string "SELECT * FROM dv_principal where" to type 'Double' is not valid. '





我尝试过:





What I have tried:

SELECT * FROM dv_principal where MOTIVE='" + cmbMotive.SelectedValue + "' AND CIV_ID='" + cmbCliente.SelectedValue + " AND DUE_DATE= '"+ dtpDueDate.SelectedText+"'"


您正在开始单引号但未关闭它



You are starting a single quote but not closing it

SELECT * FROM dv_principal where MOTIVE='" + cmbMotive.SelectedValue + "' AND CIV_ID='" + cmbCliente.SelectedValue + " AND DUE_DATE= '"+ dtpDueDate.SelectedText+"'"





实施一些基本调试并查看你正在创建的字符串





Implement some basic debugging and look at the string you are creating

SELECT * FROM dv_principal where MOTIVE='Speeding' AND CIV_ID='15441151 AND DUE_DATE= '4th May 2018'





看到错误?如果值是数字,则根本不需要引号





See the mistake? If a value is numeric you don't need the quotes at all

SELECT * FROM dv_principal where MOTIVE='" + cmbMotive.SelectedValue + "' AND CIV_ID=" + cmbCliente.SelectedValue + " AND DUE_DATE= '"+ dtpDueDate.SelectedText+"'"





你应该看看使用参数化查询也是因为您的代码对SQL注入攻击是开放的,并且考虑到数据的明显敏感性,您需要确保它受到保护。



PS请注意,如果您对此的回复仍然不起作用并没有给予任何足够的信息来帮助您,那么您对日期的处理看起来很可疑,这将是我接下来要做的事情。



You should look to use parameterised queries also as your code is open to SQL Injection attacks, and given the obviously sensitive nature of the data it's something you need to ensure is protected.

PS Note that if your response to this is "still doesn't work" that does not give anyone enough information to help you, your handling of dates looks suspect so that would be the next thing I'd look at.


这篇关于如何使用3个组合框作为过滤器从单个表中过滤数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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