数据库查询怎么会少一条记录
连到数据库后查询总是会少一条记录,而且查询出来的数据排序也和数据库里不一样。哪里有问题?
下图为数据库里数据
下图为查询结果,查的是“2”
- C/C++ code
if (!ADOQuery1->Eof){ Edit2->Text=ADOQuery1->FieldByName("date")->AsDateTime; Edit3->Text=ADOQuery1->FieldByName("time")->AsDateTime; Edit4->Text=ADOQuery1->FieldByName("NT")->AsString; Edit5->Text=ADOQuery1->FieldByName("WT")->AsString; Edit6->Text=ADOQuery1->FieldByName("GT")->AsString; int q=ADOQuery1->RecordCount;if(ADOQuery1->FindFirst()) //查找结果集中的第一条记录{ StringGrid1-> Align=alClient; StringGrid1->RowCount=q; //设置StringGrid1的总行数 StringGrid1-> ColCount=8; StringGrid1-> Cells[1][0]= "姓名 "; StringGrid1-> Cells[2][0]= "日期 "; StringGrid1-> Cells[3][0]= "时间 "; StringGrid1-> Cells[4][0]= "G.T. "; StringGrid1-> Cells[5][0]= "W.T. "; StringGrid1-> Cells[6][0]= "G.T. "; int m=0; while(m<q) { if(ADOQuery1->FindNext()) //查找结果集中的下一条记录,是不是这里有问题? { StringGrid1-> Cells[1][m+1]= ADOQuery1->FieldByName("peifang")->AsString; StringGrid1-> Cells[2][m+1]= ADOQuery1->FieldByName("date")->AsDateTime; StringGrid1-> Cells[3][m+1]= ADOQuery1->FieldByName("time")->AsDateTime; StringGrid1-> Cells[4][m+1]= ADOQuery1->FieldByName("NT")->AsString; StringGrid1-> Cells[5][m+1]= ADOQuery1->FieldByName("WT")->AsString; StringGrid1-> Cells[6][m+1]= ADOQuery1->FieldByName("GT")->AsString; } m++; }}[解决办法]
StringGrid1-> ColCount=8;
StringGrid1-> Cells[1][0]= "姓名 ";
StringGrid1-> Cells[2][0]= "日期 ";
StringGrid1-> Cells[3][0]= "时间 ";
StringGrid1-> Cells[4][0]= "G.T. ";
StringGrid1-> Cells[5][0]= "W.T. ";
StringGrid1-> Cells[6][0]= "G.T. ";
int q=ADOQuery1->RecordCount;
StringGrid1->RowCount=q + 1; //设置StringGrid1的总行数
ADOQuery1->First();
for ( int i=0, row=1; i<q; i++, row++ ) {
StringGrid1-> Cells[1][row]= ADOQuery1->FieldByName("peifang")->AsString;
StringGrid1-> Cells[2][row]= ADOQuery1->FieldByName("date")->AsDateTime;
StringGrid1-> Cells[3][row]= ADOQuery1->FieldByName("time")->AsDateTime;
StringGrid1-> Cells[4][row]= ADOQuery1->FieldByName("NT")->AsString;
StringGrid1-> Cells[5][row]= ADOQuery1->FieldByName("WT")->AsString;
StringGrid1-> Cells[6][row]= ADOQuery1->FieldByName("GT")->AsString;
ADOQuery1->Next();
}