BCB中数据库访问的问题
我用这样两句代码访问数据库,
ADOQuery2->SQL->Text = "select docCname from dbo.Doctemplate where type=1"; try{ ADOQuery2->ExecSQL(); }catch(...){Application->MessageBoxA("数据库连接错误","系统提示");}
AnsiString username = Trim(ADOQuery2->FieldByName("username")->AsString);
ADOQuery2->SQL->Text = "select docCname from dbo.Doctemplate where type=1";ADOQuery2->Open();for (int i = 0; i < ADOQuery2->RecordCount; i++){ username = Trim(ADOQuery2->FieldByName("username")->AsString); ... ADOQuery2->Next();}
[解决办法]
来个循环
ADOQuery1->Close();ADOQuery1->SQL->Text = "select docCname from dbo.Doctemplate where type=1";ADOQuery1->Open();while( !ADOQuery1->Eof){ ADOQuery1->FieldByName("")->Value}