Recent

Author Topic: InsertSQL  (Read 3329 times)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
InsertSQL
« on: October 14, 2017, 08:47:42 am »
Cannot insert Record.
What Wrong am i doing.

Code: Pascal  [Select][+][-]
  1.   Query.SQL.Add('Insert into Test(name) values(' +  '''Rohit''' + ')');
  2.   Query.ExecSQL;
 
Holiday season is online now. :-)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: InsertSQL
« Reply #1 on: October 14, 2017, 08:54:58 am »
This also not Working....

Code: Pascal  [Select][+][-]
  1.   Query.InsertSQL.Add('Insert into Test(name) values(' +  '''Rohit''' + ')');
  2.   Query.Open;
Holiday season is online now. :-)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: InsertSQL
« Reply #2 on: October 14, 2017, 09:15:14 am »
ins't name a keyword in SQL? have you tried to enclose in double quotes or the escape character of your server?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: InsertSQL
« Reply #3 on: October 14, 2017, 09:28:25 am »
Tried. used other words in place of name. but not working.
using
Code: Pascal  [Select][+][-]
  1. MSSQL SERVER 2008R2 EXPRESS EDITION
« Last Edit: October 14, 2017, 09:32:48 am by Deepaak »
Holiday season is online now. :-)

fred

  • Full Member
  • ***
  • Posts: 201
Re: InsertSQL
« Reply #4 on: October 14, 2017, 09:35:06 am »
What error do you get?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: InsertSQL
« Reply #5 on: October 14, 2017, 09:41:39 am »
I'm guessing you have a table named Test which has a field named name in that case this should work
Code: Pascal  [Select][+][-]
  1. Query.SQL.Text := 'INSERT INTO Test ([Name]) VALUES('+QuotedStr('Rohit')+')';
  2. Query.ExecSQL;
  3.  

SQL.TExt must be
Code: SQL  [Select][+][-]
  1. INSERT INTO Test ([Name]) VALUES('Rohit')
  2.  

This command is correct. if it does not execute then you have a problem with the connection chain post a sample so we can try.
« Last Edit: October 14, 2017, 09:44:40 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: InsertSQL
« Reply #6 on: October 14, 2017, 10:24:49 am »
UR's Query is Executing Without any Errors.
But values are not inserted inside table.

Select * from Test;
is working fine.
Connection through ODBC is OK.
ODBC1.Connected result is TRUE.

Code: Pascal  [Select][+][-]
  1. Query.SQL.Text:='INSERT INTO Test ([Name]) VALUES(' + '''Rohit''' + ')';
  2. Query.Execute;

no error in LazIde. Its working but Fail to Insert Record.

I Came around
Query.InsertSQL //Any workaround for this statement. Will this, will Work;
Holiday season is online now. :-)

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: InsertSQL
« Reply #7 on: October 14, 2017, 10:51:06 am »
I'm assuming that at some point after the InsertSQL query you are doing a Query.ApplyUpdates and a Transaction.Commit or .CommitRetaining? Just checking  :)
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

 

TinyPortal © 2005-2018