数据库编程里面使用Parameters和不使用的异同。
先看代码
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add( "select * from test..branch where branch = " +Edit1->Text );
ADOQuery1->Open();
}
//---------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add( "select * from test..branch where branch = :a ");
ADOQuery1->Parameters->ParamValues["a"] = Edit1->Text;
ADOQuery1->Open();
}