我想实现这样一个功能:
输入一个字段名字,输入一个要查询的值,然后让数据库返回字段值与这个查询值相同的所有记录.其中字段的类型可能为大部分常用字段,比如文本的,整形的,浮点的,日期时间等等(不包括二进制等).
有没有比较简洁的解决办法??

解决方案 »

  1.   

    意识是,应用软件的人,他怎么知道表中的字段名称呢?
    -------------------------------
    晕,开发软件的人总知道吧?你根据字段名再去查字段的类型,然后再做成SQL语句查询数据库
      

  2.   

    这样的话就不是一个通用的查询了,程序里会有根据字段类型而存在的许多的case语句了.我也不知道有没有这种查询方式,所以问一下大家.
      

  3.   

    dbgrid1.Fields[i].DisplayText 可实现以上功能
      

  4.   

      列出 DBGrid中Column的Name && DisplayText ,同时列出对应的数据库表字段名
      Search的时候对不同的字段类型做判断处理
      这个可以做成通用的模块
      

  5.   

    用字段的DataType决定SQL应该是怎么样的。
    dbgrid1.Fields[i].DataTypeTFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord,
        ftBoolean, ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime,
        ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic, ftFmtMemo,
        ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor, ftFixedChar, ftWideString,
        ftLargeint, ftADT, ftArray, ftReference, ftDataSet, ftOraBlob, ftOraClob,
        ftVariant, ftInterface, ftIDispatch, ftGuid, ftTimeStamp, ftFMTBcd);strSql := 'select * from table where 1>0';
    case dbgrid1.Fields[i].DataType of
      ftString: strSql := strSql+' and '+dbgrid1.Fields[i].fieldname+' like '''+value+'%''';
      ftDate  : strSql := strSql+' and 'dbgrid1.Fields[i].fieldname+'>='''+fromDate+'''';
      ...
    end;