C++ builder資料庫連接大全
來源:互聯網
上載者:User
最近在用BCB做個小項目,因為自己沒學過C++,BCB也是第一次接觸所以想在網上找點資料,但發現BCB的東西很少,而且關於資料庫操作方面的東西都說的很籠統,不能給找資料的人提供協助,所以我就把自己知道的一點關於BCB資料庫方面的一點東西分享給大家,希望對初學者有所協助。1.資料庫的查詢 Query1->Close(); Query1->SQL->Clear(); Query1->SQL->Add("select soft_name,soft_vision,soft_org from soft_info where "); Query1->SQL->Add("host_ip='192.168.1.111'"); Query1->ExecSQL(); //上面是將結果集儲存在Query1中int q=Query1->RecordCount;if(Query1->FindFirst()) //尋找結果集中的第一條記錄{ a=Query1->operator []("soft_name"); b=Query1->operator []("soft_vision"); c=Query1->operator []("soft_org"); Memo1->Lines->Add(" Èí¼þÃû£º"+a); Memo1->Lines->Add(" Èí¼þ°æ±¾£º"+b); Memo1->Lines->Add(" Èí¼þÉÌ£º"+c); Memo1->Lines->Add(""); int m=1; while(m<q){ if(Query1->FindNext()) //尋找結果集中的下一條記錄 { a=Query1->operator []("soft_name"); b=Query1->operator []("soft_vision"); c=Query1->operator []("soft_org"); Memo1->Lines->Add(" Èí¼þÃû£º"+a); Memo1->Lines->Add(" Èí¼þ°æ±¾£º"+b); Memo1->Lines->Add(" Èí¼þÉÌ£º"+c); Memo1->Lines->Add(""); } m++; }}//上面是將每條記錄存到控制項中2.資料庫的添加Query1->Close();Query1->SQL->Clear();Query1->SQL->Add("insert into soft_info (soft_name,soft_vision,soft_org,host_ip) values ('");Query1->SQL->Add(name->operator [](j)+"','");Query1->SQL->Add(version->operator [](j)+"','");Query1->SQL->Add(pub->operator [](j)+"','");Query1->SQL->Add("109.128.10."+AnsiString(j+1)+"')");Query1->ExecSQL();3.資料庫的刪除Query1->Close();Query1->SQL->Clear();Query1->SQL->Add("delete from soft_info");Query1->ExecSQL();Query1->DataSource->DataSet->Refresh();