Recent

Author Topic: Error Insert Query  (Read 2217 times)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Error Insert Query
« on: October 20, 2017, 01:08:59 pm »
MSSQL Server 2008

Cannot Execute. How to put comma between in two or more field name.
Code: Pascal  [Select][+][-]
  1. Query.SQL.Text:='INSERT INTO Info(Email, Phone) values(' + QuotedStr(edtEmail.Text)+ ''',''' + QuotedStr(edtphone.Text) + ')';
Holiday season is online now. :-)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Error Insert Query
« Reply #1 on: October 20, 2017, 01:12:16 pm »
Code: Pascal  [Select][+][-]
  1. Query.SQL.Text:='INSERT INTO Info(Email, Phone) values(' + QuotedStr(edtEmail.Text)+ ',' + QuotedStr(edtphone.Text) + ')';
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: Error Insert Query
« Reply #2 on: October 20, 2017, 01:20:01 pm »
Thanks...
Holiday season is online now. :-)

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Error Insert Query
« Reply #3 on: October 20, 2017, 01:20:25 pm »
Or how about:
Code: Pascal  [Select][+][-]
  1.   Query.SQL.Text := 'INSERT INTO Info(Email, Phone) values(:email, :phone)';
  2.   Query.ParamByName('email').AsString := edtEmail.Text;
  3.   Query.ParamByName('phone').AsString := edtphone.Text;
It's better to use parameters anyway.

 

TinyPortal © 2005-2018