無論我雙擊001還是其他記錄,該ADODataSet1->FieldByName("員工號")->AsString顯示的就是001的值,不曾改變。代碼如下
AnsiString Path;
AnsiString sqlstr = "Select 頭像 from Photo where 員工號='"+ADODataSet1->FieldByName("員工號")->AsString+"'";
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add(sqlstr);
ADOQuery1->Open();
Path = ADOQuery1->FieldByName("頭像")->AsString;
Image1->Picture->LoadFromFile(Path);
這個要看你的代碼是寫在什麼地方的了,試試下面的:
void __fastcall TForm1::DBGrid1DblClick(TObject Sender)//雙擊
{
if(((TDBGrid)Sender)->DataSource->DataSet->Active==false || ((TDBGrid*)Sender)->DataSource->DataSet->RecordCount<=0)return;
AnsiString Path;
AnsiString sqlstr = "Select 頭像 from Photo where 員工號='"+((TDBGrid*)Sender)->DataSource->DataSet->FieldByName("員工號")->AsString+"'";
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add(sqlstr);
ADOQuery1->Open();
Path = ADOQuery1->FieldByName("頭像")->AsString;
Image1->Picture->LoadFromFile(Path);
}
還有一點,你的員工號是文本類型的還是數字類型的,數字類型的話不要加''