To create parameters at runtime, you can use the
SQLQuery1.ParamByName('Capital').AsString := Edit1.Text;
SQLQuery1->ParamByName("Capital")->AsString = Edit1->Text;
The same code can be rewritten using the Params property, using an index of 0 (assuming the :Capital parameter is the first parameter in the SQL statement):
SQLQuery1.Params[0].AsString := Edit1.Text;
SQLQuery1->Params->Items[0]->AsString = Edit1->Text;
The command line below sets three parameters at once, using the Params.ParamValues property:
Query1.Params.ParamValues['Name;Capital;Continent'] := VarArrayOf([Edit1.Text, Edit2.Text, Edit3.Text]);
Query1->Params->ParamValues["Name;Capital;Continent"] = VarArrayOf(OPENARRAY(Variant, (Edit1->Text, Edit2->Text, Edit3->Text)));
Note that ParamValues uses Variants, avoiding the need to cast values.
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|