Passing Parameters to an Update Query 
Author Message
 Passing Parameters to an Update Query

Hi,

I am working on an TUpdateSQL query and I need to be able to pass parameters
from text boxes on the form to the SQL statement.  I keep getting errors.

Here is the code that I've been working with:

begin

   with tblClaims.UpdateObject as TUpdateSQL do
   begin
     tblClaims.CachedUpdates := true;
     SQL[ukModify].Text := format('UPDATE Claims SET InvoiceNumber = %s
WHERE ClaimID = %s',
     [Invoice.text, Claim.text]);
     ExecSQL(ukModify);
     tblClaims.ApplyUpdates;
     tblClaims.CachedUpdates := False;
   end;

end;

Also, how can I create a DBGrid at runtime?

I'd certainly appreciate help!

Thanks,
Misty  =)



Wed, 18 Jun 1902 08:00:00 GMT  
 Passing Parameters to an Update Query
Hi.

Here is a sample from one of my programs, it's not an update but I think it
will
get you where you want to go.

  if not QryByCode.Prepared then
  begin
     QryByCode.SQL.Clear;
     QryByCode.SQL.Add('select DataValue ' +
                            'from Fields '  +
                            'where  FieldID    = :FieldID ' +
                            '  and  LanguageID = :LanguageID ' +
                            '  and  DataCode   = :DataCode ' );
     QryByCode.Prepare;
  end;

  QryByCode.ParamByName('FieldID').AsString      := UpperCase(m_FieldID);
  QryByCode.ParamByName('LanguageID').AsString   := UpperCase(m_LanguageID);
  QryByCode.ParamByName('DataCode').AsString     := UpperCase(m_DataCode);

  QryByCode.Open;

  if (QryByCode.BOF and QryByCode.EOF) then
  begin
     result := m_DataCode;
     QryByCode.Close;
     exit;
  end;

   QryByCode.First;

   result := QryByCode.FieldByName('DataValue').asString;

   QryByCode.Close;


Quote:
> Hi,

> I am working on an TUpdateSQL query and I need to be able to pass
parameters
> from text boxes on the form to the SQL statement.  I keep getting errors.

> Here is the code that I've been working with:

> begin

>    with tblClaims.UpdateObject as TUpdateSQL do
>    begin
>      tblClaims.CachedUpdates := true;
>      SQL[ukModify].Text := format('UPDATE Claims SET InvoiceNumber = %s
> WHERE ClaimID = %s',
>      [Invoice.text, Claim.text]);
>      ExecSQL(ukModify);
>      tblClaims.ApplyUpdates;
>      tblClaims.CachedUpdates := False;
>    end;

> end;

> Also, how can I create a DBGrid at runtime?

> I'd certainly appreciate help!

> Thanks,
> Misty  =)




Wed, 18 Jun 1902 08:00:00 GMT  
 Passing Parameters to an Update Query
1)
Try using a colon (:) where you use a percent (%). Might be dependant upon
the type of database you are using, but it runs with a colon against Oracle.

2)
var
  Grid: TDBGrid;
begin
  Grid:=TDBGrid.Create(Self);
  // Now set props
end;

3)
Do not crosspost to such a huge list of newsgroups.

Wilco

Quote:

>Hi,

>I am working on an TUpdateSQL query and I need to be able to pass
parameters
>from text boxes on the form to the SQL statement.  I keep getting errors.

>Here is the code that I've been working with:

>begin

>   with tblClaims.UpdateObject as TUpdateSQL do
>   begin
>     tblClaims.CachedUpdates := true;
>     SQL[ukModify].Text := format('UPDATE Claims SET InvoiceNumber = %s
>WHERE ClaimID = %s',
>     [Invoice.text, Claim.text]);
>     ExecSQL(ukModify);
>     tblClaims.ApplyUpdates;
>     tblClaims.CachedUpdates := False;
>   end;

>end;

>Also, how can I create a DBGrid at runtime?

>I'd certainly appreciate help!

>Thanks,
>Misty  =)




Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Parameter Query not passing Param

2. SQL Query: How to pass parameters b/n tabs

3. Passing SQL Query Parameters to RemoteData Servers

4. Parameter Passing query

5. MySQL ODBC 3.51 and passing a date as parameter to a query

6. How to pass a parameter for an SQL query where the parameter is a substring of the field?

7. Passing parameters to stored procedure.

8. Pass a TTable as Parameter to another object.

9. Passing TMemoField as a TStringList parameter to a procedure

10. Access 97 report from Delphi and passing parameters

11. passing SQL parameters

12. Passing functions as parameters in Turbo Pascal

 

 
Powered by phpBB® Forum Software