Jump to content
PenelopeSkye

Missing CommandText property

Recommended Posts

I am trying to insert into a database.  I am using the code below.  When I run the code I get the error message also below.

It is my understanding that the command text is only if you are using a sql statement which I am not.  

What am I missing?  Thanks!

 

procedure TfDesignMaster.btnAddUserClick(Sender: TObject);
var
   userstring,OldValue: string;
begin

 with dm do
   begin
      userstring := CurrentUserName;
      OldValue := dbedit23.text;

 

      dsetAddUser.Open;
      

      tbAddUser.Insert;
      tbAddUser['JM_User'] := userstring;
      tbAddUser['OldValue'] := DBEdit23.Text;
      tbAddUser.Post;
     end;
end;

 

 

image.png.3f00cd8fde3f8f7a04d94d51e9c7ccbb.png

Share this post


Link to post

Hi,
Generally, I use this syntax

      tbAddUser.Insert;
      tbAddUser.FieldByName('JM_User').asString := userstring;
      tbAddUser.FieldByName('OldValue').asString := DBEdit23.Text;
      tbAddUser.Post; 

 

Share this post


Link to post

too little information

... SQL gets used either way.

 

my shortcut: ctrl+j->mydummy

with cdsDUMMY do
   begin
    Close; Params.Clear; IndexName := '';
    CommandText := '';
    Params.ParseSQL(CommandText,True);
    Params.ParamByName('').AssignFieldValue();
    Open;
   end;

depends on architecture - maybe apply latter 🙂

regards

Share this post


Link to post

There may be a CommandType to select what the commandText does with its string. 

 

I would use SQL perhaps to check if the newusername is already used ("spoken for" as we say here), then do the insert.  But that may be the crew in charge of new user account to check for duplicate users.  

Share this post


Link to post

What types are dsetAddUser and tbAddUser and how are they related?

Where do you specify the table name the insertion is supposed to go?

Share this post


Link to post

Oh for Heaven's sake, of course on the day I already responded that I wasn't getting it I kept noodling and found a website that said for insert and update you should use TADOCommand.

 

The following works.  Thanks everyone!

 

procedure TfDesignMaster.btnAddUserClick(Sender: TObject);
var
   CommandText,userstring,OldValue,qstring: string;
   
begin

with dm do
begin
 userstring := CurrentUserName;
 OldValue := dbedit23.text;
 qString :=   'INSERT INTO AdimsUserField (JM_User,OldValue)  VALUES (:a, :b)';

 commandAddUser.CommandText := qstring;
 commandAddUser.Parameters.FindParam('a').Value := 'stuff';
 commandAddUser.Parameters.FindParam('b').Value := OldValue;

 commandAddUser.Execute();
 ShowMessage(userstring);
   end;
end;

Edited by PenelopeSkye

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×