跪求vb查询数据库数值的程序

来源:百度知道 编辑:UC知道 时间:2024/06/23 08:39:35
我有两个combo控件,我想根据用户所选择的选项,查出数据库表格对应的数据,其中两个combo所选择的是表格的横排和竖排,要返表中combo所选的两个字符串相对应的一个数据。数据库名为GearDatabase.mdb 表名是gearka,小弟是菜鸟,望高手指教!!!
我得是第二种情况!!谢谢

你的题写的我不是很明白

情况一:
是根据指定两个字段的值查询,可以用下面的代码。

'将两个combo控件的style属性设置为2,下面将生成SQL查询语句。
'我是直接在这写的,没有在VB下面试,不过应该是不会有错的吧

dim sql
sql="select * from gearka"
if combo1.ListIndex <>-1 or combo2.ListIndex<>-1 then
sql=sql & " where"
end if
if combo1.ListIndex<>-1 then
sql =sql & " 字段名1='"& combo1.text &"'"
if combo2.ListIndex<>-1 then
sql=sql & " and"
end if
end if
if combo2.ListIndex<>-1 then
sql =sql & " 字段名2='"& combo2.text &"'"
end if

情况二:
情况比较复杂(要打好多字^_^)

数据库 例

名称 | 00年价格 | 01年价格 | 02年价格
手机 | 1000元 | 1200元 | 1300元
电脑 | 3000元 | 2800元 | 5000元
大饼 | 5000元 | 6000元 | 7000元

combo1 | combo2
手 机 | 00年价格
电 脑 | 01年价格