adoquery1.SQL.Clear ;
adoquery1.SQL.Add('select * from yssj where IP地址='+str[0]+' and MAC地址='+str[4]+'');
adoquery1.Open;
if adoquery1.RecordCount=0 then showmessage('+str[5]+'+'的计算机使用非法IP地址')

解决方案 »

  1.   

    adoquery1.close;
    adoquery1.SQL.Clear ;
    adoquery1.SQL.Add('select * from yssj where IP地址='''+str[0]+''' and MAC地址='''+str[4]+'''');
    try
      adoquery1.Open;
      if adoquery1.RecordCount=0 then showmessage(str[5]+'的计算机使用非法IP地址')
    except
      showmessage('Error');
    end;
      

  2.   

    adoquery1.SQL.Clear ;
    adoquery1.SQL.Add('select * from yssj where IP地址='+str[0]+' and MAC地址='+str[4]+'');
    adoquery1.Open;
    if (adoquery1.IsEmpty) then showmessage('+str[5]+'+'的计算机使用非法IP地址')
      

  3.   

    阿,来晚了。。-----------
    adoquery1.close;
    adoquery1.SQL.Clear ;
    adoquery1.SQL.Text:='select * from yssj where IP地址='''+str[0]+''' and MAC地址='''+str[4]+'''';
    try
      adoquery1.Open;
      if adoquery1.RecordCount=0 then showmessage(str[5]+'的计算机使用非法IP地址')
    except
      showmessage('Error');
    end;
    还有,最好不要使用中文字段名称
      

  4.   

    唉,又是SQL语句里的引号问题。
    类似的帖子真多呀。
      

  5.   

    adoquery1.SQL.Clear ;
    adoquery1.SQL.Add('select * from yssj');
    ADOQuery1.SQL.Add('where IP地址=:IP');
    ADOQuery1.SQL.Add('and MAC地址=:MAC');
    ADOQuery1.Parameters.ParamByName('IP').Value:=str[0];
    ADOQuery1.Parameters.ParamByName('MAC').Value:=str[4];
    ADOQuery1.Open ;
    if adoquery1.RecordCount=0 then showmessage('+str[5]+'+'的计算机使用非法IP地址');
    ADOQuery1.Close;
    我这样解决了
      

  6.   

    下面代码的功能是:将ListView中的内容导入到数据库中,之前并进行分析,和数据库中已有的表进行比较,找出ListView中和表中不同的记录!
    存在一些错误,请指教!
    for j:=0 to (CurListView.Columns.Count - 1)
      do s_h[j]:=trim(FixLenStr(CurListView.Columns[j].Caption, 15));
      ADOConnection1.Execute('create table '+newtableName+'('+s_h[0]+' char(50),'+s_h[1]+' char(50),'+s_h[2]+' char(50),'+s_h[3]+' char(50),'+s_h[4]+' char(50))');  for i:=0 to CurListView.Items.Count-1 do
        begin
         str[0] := FixLenStr(CurListView.Items[i].Caption, 15) ;
          for j:=0 to (CurListView.Items[i].SubItems.Count-2) do
            str[j+1] :=FixLenStr(CurListView.Items[i].SubItems[j], 15);        //判断
             ADOQuery1.SQL.Clear ;
             ADOQuery1.SQL.Add('select * from yssj where IP地址=:IP');
             //ADOQuery1.SQL.Add('where IP地址=:IP');
             ADOQuery1.Parameters.ParamByName('IP').Value:=str[0];
             ADOQuery1.Open ;
             //ADOQuery1.FindFirst;
             //ADOQuery1.FieldByName('IP地址');
             if ADOQuery1.RecordCount=0 then showmessage('非法的计算机')
             else
              begin
               adoquery1.SQL.Clear ;
               adoquery1.SQL.Add('select * from yssj where IP地址=:IP and MAC地址=:MAC');
               //ADOQuery1.SQL.Add('where IP地址=:IP');
               //ADOQuery1.SQL.Add('and MAC地址=:MAC');
               ADOQuery1.Parameters.ParamByName('IP').Value:=str[0];
               ADOQuery1.Parameters.ParamByName('MAC').Value:=str[4];
               try
                 ADOQuery1.Open ;
                 if adoquery1.RecordCount=0 then showmessage('+str[5]+'+'的计算机使用非法IP地址');
               except
                  showmessage('error')
               end;
             end;
             ADOQuery1.Close;
             FreeAndNil(ADOQuery1);         ADOConnection1.Execute('insert into '+newtableName+' ('+s_h[0]+' ,'+s_h[1]+' ,'+s_h[2]+' ,'+s_h[3]+' ,'+s_h[4]+')  values ('+chr(39)+str[0]+chr(39)+','+chr(39)+trim(str[1])+chr(39)+','+chr(39)+trim(str[2])+chr(39)+','+chr(39)+trim(str[3])+chr(39)+','+chr(39)+trim(str[4])+chr(39)+')')    end;