原来以为是这里有问题,查了三次没发现问题,后来终于发现问题出在上面的一段Code里,{}没有对应,傻了。。。。
void __fastcall TForm1::Button2Click(TObject *Sender)
{
{
String cxpf,mysql;
cxpf=Edit3->Text;
mysql="select * from record where peifang = '" + cxpf + "' ORDER BY PID";
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add(mysql);
ADOQuery1->Open();
if (!ADOQuery1->Eof)
{
int q=ADOQuery1->RecordCount;
// StringGrid1-> Align=alClient;
StringGrid1->RowCount=q+1; //设置StringGrid1的总行数
StringGrid1-> ColCount=5;
StringGrid1->ColWidths[4]=120;
StringGrid1-> Cells[1][0]= " 配方";
StringGrid1-> Cells[2][0]= " 细料代号 ";
StringGrid1-> Cells[3][0]= " N.W.";
StringGrid1-> Cells[4][0]= " 时间";
ADOQuery1->First();
for ( int i=0, sqlrow=1; i<q; i++, sqlrow++ ){
StringGrid1-> Cells[1][sqlrow]= ADOQuery1->FieldByName("peifang")->AsString;
StringGrid1-> Cells[2][sqlrow]= ADOQuery1->FieldByName("xiliaodaihao")->AsString;
StringGrid1-> Cells[3][sqlrow]= ADOQuery1->FieldByName("NW")->AsString;
StringGrid1-> Cells[4][sqlrow]= ADOQuery1->FieldByName("pdt")->AsDateTime; //这句日期AsDateTime可否改为AsString
ADOQuery1->Next();
}
Label3->Caption="共找到"+IntToStr(q)+"条记录";
MemoRe->Lines->Add(Now());
}
else
ShowMessage("未找到任何记录");
}
}