看看这些代码:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBTables, Grids, DBGrids, StdCtrls, QuickRpt, QRCtrls,
  ExtCtrls, DBCtrls;type
  TForm1 = class(TForm)
    DataSource1: TDataSource;
    Query1: TQuery;
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    DBGrid1: TDBGrid;
    ComboBox1: TComboBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  s,s1:TdateTime;
  
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin
if combobox1.text='' then
begin
 showmessage('请选择数据表');
 exit;
end
else
begin
 s:=strtodatetime(edit1.Text);
s1:=strtodatetime(edit2.Text);
query1.SQL.Text:='select * from  '''+combobox1.text+''' where csrq>='''+s+''' and csrq<='''+s1+'''';
query1.ExecSQL;
Query1.Close;end;
为什么老出现如此结果:
[Error] Unit1.pas(47): Incompatible types: 'String' and 'TDateTime'
[Error] Unit1.pas(47): Incompatible types我应该怎么解决!!!各位高手赐教!!!
end;end.

解决方案 »

  1.   

    s:=edit1.Text;
    s1:=edit2.Text;就可以了。不用转化类型
      

  2.   

    这样就行了:
    s:=strtodatetime(edit1.Text);
    s1:=strtodatetime(edit2.Text);
    query1.SQL.Text:='select * from  '''+combobox1.text+''' where csrq>='''+DatetimetoStr(s)+''' and csrq<='''+DatetimetoStr(s1)+'''';
    query1.ExecSQL;
    Query1.Close;
    或者
    query1.SQL.Text:='select * from  '''+combobox1.text+''' where csrq>='''+Edit1.Tex+''' and csrq<='''+Edit2.Text+'''';
      

  3.   

    query1.SQL.Text必须是string类型的,你看看你的代码里面,s是DateTime类型的,怎么匹配呢?
      

  4.   

    对,你说得没错,不过csrq在oracle表中定义的为data型,这样string类型的s.s1能与csrq比较大小吗?csrq为日期型呀!
      

  5.   

    query1.SQL.Text:='select * from  '''+combobox1.text+''' where csrq>='''+s+''' and csrq<='''+s1+'''';
    s和s1都是DATETIME ,不是STRING,错误简化为
    var l_string:string;
    l_string:=s(DATETIME型) 中的错误
      

  6.   

    s:=strtodatetime(edit1.Text);
    s1:=strtodatetime(edit2.Text);
    query1.SQL.Text:='select * from  '+combobox1.text+ ' where csrq between :ss and :tt';
    query1.ParamByName('ss').asdate:= s;
    query1.ParamByName('tt').asdate:= s1
    query1.ExecSQL;
    Query1.Close;
      

  7.   

    query1.ParamByName('ss').asdate:= strtodate(edit1.Text);
    query1.ParamByName('tt').asdate:= strtodate(edit2.Text);
      

  8.   

    query1.SQL.Text:='select * from  '''+combobox1.text+''' where csrq>='''+s+''' and csrq<='''+s1+'''';在这行里,用加号连接的需要string,不能直接Tdatetime的变量