对DBGrid 的巧妙用法实现查询

类别:编程语言 点击:0 评论:0 推荐:

void __fastcall TForm1::DBGrid2DblClick(TObject *Sender)
{
  // INGOODS‘ 是进货表


   int sumno=0,i;


   INGOODS->Edit();
file://-----------------------------------------------------
   AnsiString thisgoodsname;
   DBGrid2->SelectedIndex=1;
   thisgoodsname=DBGrid2->SelectedField->Value;
   file://ShowMessage(thisgoodsname);
//
file://-----------------------------------------------------
   Query2->Close();
   Query2->SQL->Clear();
   Query2->DatabaseName=".\\";
   Query2->SQL->Add("Select * from INGOODS");
   Query2->SQL->Add("where GOODSNAME='"+thisgoodsname+"'");
   Query2->Prepare();
   Query2->Open();
   for(i=0;i<Query2->RecordCount;i++){
      sumno+=Query2->FieldByName("INGOODSNO")->AsInteger;
      Query2->Next();
   }
   Form4=new TForm4(this);
   Form4->DBText1->DataSource=DataSource1;
   Form4->DBText1->DataField="ID";
   Form4->DBText2->DataSource=DataSource1;
   Form4->DBText2->DataField="GOODSNAME";
   Form4->DBText3->DataSource=DataSource1;
   Form4->DBText3->DataField="CLASS";
   Form4->DBText4->DataSource=DataSource1;
   Form4->DBText4->DataField="THENMAN";
   Form4->Label5->Caption="最近出货时间: ";
   Form4->DBText5->DataSource=DataSource1;
   Form4->DBText5->DataField="LASTTIME";
   Form4->Label6->Caption="现总销售量:";
   file://Form4->DBText6->DataSource=DataSource1;
   file://Form4->DBText6->DataField="THISGOODSNO";
   Form4->Label7->Caption=IntToStr(sumno);
   file://Form4->Edit2->Text=
   Form4->Show();
}

本文地址:http://com.8s8s.com/it/it29791.htm