用select来读取数据时的问题:
    有两个数值,a和b是两个数值型,在用select来读取数据,我用 "字段名 BETWEEN a and b",但在
运行时提示数据不符。
   程序如下: a=request("aa")
              b=request("bb")
              select * from flea where flea_xz BETWEEN '" + a + "' and '" + b + "'"
  请问一下,select语句该怎么写!

解决方案 »

  1.   

    "select * from flea where flea_xz BETWEEN " + a + " and " + b
    把单引号都去掉。
      

  2.   

    需显式声明a和b
    int a=request("aa");
    int b=request("bb");
    string strSelect="select * from flea where flea_xz BETWEEN " + a + " and " + b;
    把单引号都去掉。
      

  3.   

    你可以把sql语句在调式模式下取出来 放在查询分析器中执行,看看是什么错误
      

  4.   

    曾经用过:把+ 改为& ,或者需显式声明a和b
      

  5.   

    a=Convert.ToInt32(request("aa"))
    b=Convert.ToInt32(request("bb"))
    string strSelect = "select * from flea where flea_xz BETWEEN '" + a + "' and '" + b + "'"
      

  6.   

    a=Convert.ToInt32(request("aa"))
    b=Convert.ToInt32(request("bb"))
    string strSelect = "select * from flea where flea_xz BETWEEN " + a + " and " + b + ""---------------
    把 单引号 去掉.试试. (感谢楼上的)
      

  7.   

    '" + a + "' and '" + b + "'
    把单引号去掉----->变成  " + a + " and " + b + "或者,
    把+改成&------->变成  '" & a & "' and '" & b +&"'
      

  8.   

    Sql语句最好写成存储过程或参数化查询语句就没有这个问题了。