Hi Cosmin,
> I'm learning ASP.NET and in the process I need to learn ADO.NET; The
> syntax for defining and using a SQL query that makes use of parameters
> seems really difficult to me, so I hope I'm actually missing something.
I'm using a special routine that I wrote to add parameters to a
parameterised query.
> X := FbCommand.Create('SELECT * FROM TAB WHERE ID=?', Connection,
> Transaction);
> X.Parameters.Add('', DbType.&String).Value := '7';
This is what I would do:
Command := BdpCommand.Create('SELECT * FROM TAB WHERE ID = ?',
Connection, Transaction);
// add parameters, assume ID of type String, length 15
AddParameterToCommand(Command, 'ID', BdpType.&String, 15, '42');
With the following support routine:
procedure AddParameterToCommand(var Command: BdpCommand;
const Name: String;
&Type: BdpType; Size: Integer; Value: TObject);
var
Parameter: Borland.Data.Common.BdpParameter;
begin
Parameter := BdpParameter.Create(Name, &Type, Size);
Parameter.Value := Value;
Parameter.Direction := ParameterDirection.Input;
Parameter.SourceColumn := Name;
Command.Parameters.Add(Parameter);
{$IFDEF DEBUG}
context.trace.Write('Parameter ' + Parameter.ParameterName +
' = [' + Parameter.Value.ToString + ']')
{$ENDIF}
end;
As you can see, the connection to the SourceColumn will ensure that you
can even call AddParameterToCommand in the "wrong" order (of parameters)
is you wish.
> Am I missing something? I sure hope I'm missing something...
Described and used in more detail in my ASP.NET courseware manuals by
the way.
> Thanks,
> Cosmin Prund
Groetjes,
Bob Swart
--
Bob Swart Training & Consultancy (eBob42.com) Forever Loyal to Delphi
Blog: http://www.drbob42.com/blog - RSS: http://drbob42.com/weblog.xml
New Delphi 2006 Courseware e-books at http://www.eBob42.com/courseware
_______________________________________________
Delphi-DB mailing list
[email protected]
http://www.elists.org/mailman/listinfo/delphi-db