C++ Builder 查询数据库时出现BOF或EOF错误
首先声明我很菜,请帮忙
我用C++ Builder 查询数据库时出现BOF或EOF错误,如上图,
是不是IF 或哪个循环用错了?
哪位帮解释修正一下,程序如下:
void __fastcall TForm1::Button2Click(TObject *Sender){String cxpf,mysql;cxpf=Edit1->Text;mysql="select * from record where pf = '"+cxpf+"'";ADOQuery1->Close();ADOQuery1->SQL->Clear();ADOQuery1->SQL->Add(mysql);ADOQuery1->Open(); if(!ADOQuery1->Eof){ Edit2->Text=ADOQuery1->FieldByName("date")->AsDateTime; Edit3->Text=ADOQuery1->FieldByName("time")->AsDateTime; Edit4->Text=ADOQuery1->FieldByName("N1")->AsString; Edit5->Text=ADOQuery1->FieldByName("N2")->AsString; Edit6->Text=ADOQuery1->FieldByName("N3")->AsString; int q=ADOQuery1->RecordCount;if(ADOQuery1->FindFirst()) //查找结果集中的第一条记录{ StringGrid1-> Align=alClient; StringGrid1-> ColCount=7; StringGrid1-> Cells[1][0]= "姓名 "; StringGrid1-> Cells[2][0]= "日期 "; StringGrid1-> Cells[3][0]= "时间 "; StringGrid1-> Cells[4][0]= "数学 "; StringGrid1-> Cells[5][0]= "语文"; StringGrid1-> Cells[6][0]= "物理";//设置StringGrid1标题 StringGrid1-> Cells[1][1]= ADOQuery1->FieldByName("pf")->AsString; StringGrid1-> Cells[2][1]= ADOQuery1->FieldByName("date")->AsDateTime; StringGrid1-> Cells[3][1]= ADOQuery1->FieldByName("time")->AsDateTime; StringGrid1-> Cells[4][1]= ADOQuery1->FieldByName("N1")->AsString; StringGrid1-> Cells[5][1]= ADOQuery1->FieldByName("N2")->AsString; StringGrid1-> Cells[6][1]= ADOQuery1->FieldByName("N3")->AsString; int m=0; while(m<q) { if(ADOQuery1->FindNext()) //查找结果集中的下一条记录 { StringGrid1-> Cells[1][m+2]= ADOQuery1->FieldByName("pf")->AsString; StringGrid1-> Cells[2][m+2]= ADOQuery1->FieldByName("date")->AsDateTime; StringGrid1-> Cells[3][m+2]= ADOQuery1->FieldByName("time")->AsDateTime; StringGrid1-> Cells[4][m+2]= ADOQuery1->FieldByName("N1")->AsString; StringGrid1-> Cells[5][m+2]= ADOQuery1->FieldByName("N2")->AsString; StringGrid1-> Cells[6][m+2]= ADOQuery1->FieldByName("N3")->AsString; } m++; }} }else ShowMessage("数据库中没有该记录");}