PenelopeSkye 1 Posted September 21, 2022 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; Share this post Link to post
Pat Foley 51 Posted September 21, 2022 could be tablename or stored procedure. Source https://docwiki.embarcadero.com/Libraries/Alexandria/en/Datasnap.DBClient.TCustomClientDataSet.CommandText Share this post Link to post
Serge_G 87 Posted September 22, 2022 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
Milo G 0 Posted September 22, 2022 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
PenelopeSkye 1 Posted September 27, 2022 So far I still haven't been able to get it to work, but thank you for all the suggestions! Share this post Link to post
Pat Foley 51 Posted September 27, 2022 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
Uwe Raabe 2057 Posted September 27, 2022 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
PenelopeSkye 1 Posted September 27, 2022 (edited) 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 September 27, 2022 by PenelopeSkye Share this post Link to post