求SQL查询方法:
   要从ACCESS数据库中查询三个字段"姓名""身高""体重",VB窗体上有四个文本框heightmin,heightmax,weightmin,weightmax,分别输入身高和体重的最大值和最小值,根据输入的身高范围和体重范围查询出满足条件的记录的姓名、身高和体重,请问这个查询语句怎么写,怎样把文本框中的值赋给查询语句(直接写身高between heightmin.text and heightmax.text是不行的)

解决方案 »

  1.   

    dim sql as string
    sql = "select * from xxx where 体重 between " & heightmin.text & " and " & heightmax.text
      

  2.   

    sql=" select * from 表名 where 身高 between "& heightmin.text &" and "& heightmax.text &""
      

  3.   

    http://topic.csdn.net/u/20091118/21/6d3d3696-ee6c-4d73-9591-7a8d2543d4d3.html
      

  4.   

    dim sCmd as stringsCmd="Select * From 你的表 Where 身高 between '" & heightmin.text & "' and '" & heightmax.text&"' and/or 体重 between '" & weightmin.text & "' and '" & weightmax.text&"' "试下可以不?
      

  5.   

    以上方法都不行,提示:至少一个参数没有被指定值,好像还是文本框中的数值无法传递到SQL语句中,是否需要在textbox的change事件中写代码呢,如果需要,怎么写呢
      

  6.   

    以上方法都不行,提示:至少一个参数没有被指定值,好像还是文本框中的数值无法传递到SQL语句中,是否需要在textbox的change事件中写代码呢,如果需要,怎么写呢
      

  7.   

    都是单精度型的
    Dim strSQL As String
    strSQL = "select 姓名,身高 from mytable where 身高 between " & heightmin.Text & "and" & heightmax.Text
    将heightmin.Text 和heightmax.Text换成数字就可以
      

  8.   

    Dim strSQL As String 
    strSQL = "select 姓名,身高 from mytable where 身高 between " & val(heightmin.Text) & "and" & val(heightmax.Text)
      

  9.   


    Dim minHeitght as Single
    Dim maxHeitght as Single
    Dim minWeight as Single
    Dim maxWeight as Single
    Dim strSQL As String minHeitght = heightmin
    maxHeitght = heightmax
    minWeight = weightmin
    maxWeight = weightmaxstrSQL="select * from 表 where height between " & minHeight & " and " & maxHeight & " and weight between " & minWeight & " and " & maxWeight & "
      

  10.   

    strSQL="select * from 表 where height between " & minHeight & " and " & maxHeight & " and weight between " & minWeight & " and " & maxWeight & ""
    最后少了个双引号,更正一下
      

  11.   

    Dim strSQL As String
    strSQL = "select 姓名,身高 from mytable where 身高 between " & val(heightmin.Text) & "and" & val(heightmax.Text)""
    最后面少了两个引号,再试试
      

  12.   

    strSQL = "select [姓名], [身高] from mytable where [身高] between " & heightmin.Text & " and " & heightmax.Text and前后要加空格
      

  13.   

    Dim strSQL As String
    strSQL = "select 姓名,身高 from mytable where 身高 between " & val(heightmin.Text) & "and" & val(heightmax.Text) & ""
    应该是这样的
      

  14.   


    终于解决了,哈哈,就是and前后没加空格的问题,谢谢大家这么热心了