13,826
社区成员
发帖
与我相关
我的任务
分享
void __fastcall TForm1::Button5Click(TObject *Sender)
{
String SQL;
TStringList *List0;
List0 = new TStringList();
SQL = "create table [001](test text,id autoincrement(1,1) primary key)";
ADOQuery1->ExecSQL();
for(int i=0;i<ListBox1->Count;i++)
{
List0->Add(ListBox1->Items->Strings[i].Trim() ;
}
SQL = "insert into [001](test) values('"List0->Text"')";
ADOQuery1->ExecSQL();
}
//读出数据
void __fastcall TForm1::Button5Click(TObject *Sender)
{
AnsiString SQL = "select * from MyTable" ;
ADOQuery1->Close() ;
ADOQuery1->SQL->Clear() ;
ADOQuery1->SQL->Add(SQL) ;
ADOQuery1->Open() ;
while(!ADOQuery1->Eof)
{
ListBox1->Items->Add(ADOQuery1->FieldByName("PriKey")->AsString) ;
ADOQuery1->Next() ;
}
}
//存入数据库
void __fastcall TForm1::Button5Click(TObject *Sender)
{
for(int i=0;i<ListBox1->Count;i++)
{
AnsiString Str = ListBox1->Items->Strings[i] ;
AnsiString SQL ;
SQL.sprintf("INSERT INTO MyTable(PriKey) VALUES('%s')",Str.c_str()) ;
ADOQuery1->Close() ;
ADOQuery1->SQL->Clear() ;
ADOQuery1->SQL->Add(SQL) ;
ADOQuery1->ExecSQL() ;
}
}