The tadoconnection and tadostoreproc components should be used to execute the SQL Server Remote Storage Process in BCB. The tadoconnection component serves as the Connection database, and the tadostoreproc component serves as the running storage process.
1. Connect to the database
void __fastcall TDataModule::OpenADOConnection()
{
ADOConnection1->ConnectionString = "...";
ADOConnection1->LoginPrompt = false;
try
{
ADOConnection1->Connected = true;
}catch(...)
{
//TODO: Show Database Open Error Message
return;
}
return;
}
2. Set the Stored Procedure
(1) it is best to use a designer in BCB to set the stored procedure name of the tadostoreproc component, so that the stored procedure parameters can be automatically added. Remember to set connected of tadoconnection to false before build.
(2) Use the parameters attribute to set the stored procedure parameters at runtime.
Storedproc1-> close ();
Storedproc1-> parambyname ("@ paraid")-> asstring = edtid-> text;
// Other parameters
(3) run the stored procedure in execproc or open mode
if(!StoreProc1->Prepared)
StoreProc1->Prepare();
StoreProc1->ExecProc();
(4) The final result can be obtained through parameters or tdataset.
Label1->Caption = StoreProc1->ParamByName("@ReturnValue")->AsString;