我建了一个数据库,用adodataset取出数据,放在datagrid中,现在要实现按字段"井号"查询功能,放了一个Edit起名为txtjh,一个button名为井号查询,实现语句如下,
procedure TForm1.Button1Click(Sender: TObject);
begin
try
    adodataset1.close;
    adodataset1.CommandText:='select * from wellfinish where 井号='+txtjh.Text;
    adodataset1.Open;
  except
    messagedlg('eeeeeee',mterror,[mbok],0);
    abort;
  end;
  dbgrid1.Refresh;
end;提示错误如下:在将nvarchar值 33-211转换为int值时出现错误。注:33-211是字段井号的第一个记录。

解决方案 »

  1.   

    可以这样试试:adodataset1.CommandText:='select * from wellfinish where 井号='+'"'+txtjh.Text+'"';
      

  2.   

    33-211  : string ,不是int
      

  3.   

    井号='+txtjh.Text
    改为
    井号='''+txtjh.Text+'''
      

  4.   

    adodataset1.CommandText:='select * from wellfinish where 井号='+quotestr(txtjh.Text);
      

  5.   

    试了一下,都不行,我再说明一下,22-211是字段"井号"的第一个记录,是nchar型的。不论在Edit中输入什么数值,都会出现同一个错误提示。我想可能是类型转换的问题???为何程序编译时会自动要将记录中的数据都转换为int型呢??难道txtjh中输入的数据默认为是int型的吗??不应该啊,我记得应该是默认为string型的才对啊。
      

  6.   

    adodataset1.CommandText:='select * from wellfinish where 井号='''+txtjh.Text+'''';
      

  7.   

    试了一下,提示错误,我改成了
     adodataset1.CommandText:='select * from wellfinish where 井号='+'''+txtjh.Text''';
    能够运行,不过出不了任何结果
      

  8.   

    adodataset1.CommandText:='select * from wellfinish where Ltrim(RTrim(井号))='''+ trim(txtjh.Text) + '''';