如何查找重复记录

可以在OnColExit事件中判断。
假如你有5个字段:a,b,c,d,e;那么就定义5个String的变量:
String sa,sb,sc,se;
然后这样写:
void __fastcall TForm1::DBGrid1ColExit(TObject *Sender)
{
    int i;
    i=DBGrid1->SelectedIndex;
    switch(i)
    {
        case 0:
           sa=Trim(DBGrid1->SelectedField->Text);
           break;
        case 1:
           sb=Trim(DBGrid1->SelectedField->Text);
           if(sa==sb)
           {
             ShowMessage(sb);
             Abort();
           }
           break;
        case 2:
           sc=Trim(DBGrid1->SelectedField->Text);
           if(sc==sa||sc==sb)
           {
             ShowMessage(sc);
             Abort();
           }
           break;
        case 3:
           sd=Trim(DBGrid1->SelectedField->Text);
           ShowMessage(sa+","+sb+","+sc+","+sd);
           if(sd==sa||sd==sb||sd==sc)
           {
             ShowMessage(sd);
             Abort();
           }
           break;
        case 4:
           se=Trim(DBGrid1->SelectedField->Text);
           if(se==sa||se==sb||se==sc||se==sd)
           {
             ShowMessage(se);
             Abort();
           }
           break;
        case 5:
           sf=Trim(DBGrid1->SelectedField->Text);
           if(sf==sa||sf==sb||sf==sc||sf==sd||sf==se)
           {
               ShowMessage(sf);
               sa="";
               sb="";
               sc="";
               sd="";
               se="";
               sf="";
               Abort();
           }

           break;
    }
}

阅读更多
文章标签: string c
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭