Recent

Author Topic: Database question  (Read 5221 times)

yordan

  • New Member
  • *
  • Posts: 18
Database question
« on: December 07, 2010, 10:36:06 am »
 Hi, I'm new in Lazarus programming and I have troubles manipulating SQL database with Lazarus.
 I am trying to create a small program that inserts a new row in an existing table grupist, the code I use is:

 procedure TForm1.Button1Click(Sender: TObject);
begin
  SQLQuery1.SQL.Text:='insert into grupist (kod,name) values (12,'+ Edit1.Text + ')';
  SQLQuery1.ExecSQL;
end;   
 
 but when I execute my application I get the following message: 'MySQL50Connection1: Error executing query: Unknown column 'ZZZZZ' in field list'
 Please tell me what should I do to fix this error.
 Thanks ::)

jixian.yang

  • Full Member
  • ***
  • Posts: 173
Re: Database question
« Reply #1 on: December 07, 2010, 11:26:19 am »
There should be "Edit1.Text" if it is string:

SQLQuery1.SQL.Text:='insert into grupist (kod,name) values (12,'+ QuotedStr(Edit1.Text) + ')';

yordan

  • New Member
  • *
  • Posts: 18
Re: Database question
« Reply #2 on: December 07, 2010, 11:50:45 am »
Thanks, it works now  :D  8-)

yordan

  • New Member
  • *
  • Posts: 18
Re: Database question
« Reply #3 on: December 09, 2010, 12:27:34 pm »
Another issue occur with this program, I modified it to count the rows in the DBGrid1 in the form with: M := DBGrid1.FieldCount; and when I changed back the code and compiled it again I got the message: MySQL50Connection1: Server connect failed. I tried rewriting the program into another project after successful compiling the same error message is shown. The strangest thing is that Lazarus actually creates the exe file and when I run it it works OK.
Anyone have a clue what might have happened ?

jixian.yang

  • Full Member
  • ***
  • Posts: 173
Re: Database question
« Reply #4 on: December 09, 2010, 04:44:59 pm »
Check project.lpr.

Lacak2

  • Guest
Re: Database question
« Reply #5 on: December 13, 2010, 07:35:23 am »
I modified it to count the rows in the DBGrid1 in the form with: M := DBGrid1.FieldCount;
Count of rows ? (IMHO RecordCount, not FieldCount ;-))

 

TinyPortal © 2005-2018