Page 1 of 1
Single Quote in UNIDAC and SQL Server using Delphi
Posted: Tue 22 Feb 2011 08:56
by overvi
What is the best way to allow program to able to input single quote ?
Do i have to replace every single quote with double quote or is there other ( more automatic way ) ?
Posted: Wed 23 Feb 2011 09:31
by AndreyZ
Hello,
To input single quote from the code you can only use the following code:
Code: Select all
UniQuery.Edit;
UniQuery.FieldByName('strfld').AsString := '''test''';
UniQuery.Post;
Also you can easily input single quote using visual components.
Posted: Wed 23 Feb 2011 13:29
by overvi
Hello AndreyZ,
What do you mean by visual components ? if you mean it by using editbox, that's my problem. I want to input for example Sam's Restaurant.
so my editbox contain Sam's Restaurant.
so in my code it will look like this
Code: Select all
Uniquery.edit;
Uniquery.fieldbyname('strfld').asstring := '''+editbox1.text+''';
uniquery.post;
if i run code above, an error occured
I have to replace every single quote in editbox1.text with 2 single quote.
Is there an easier way ?
Posted: Wed 23 Feb 2011 15:29
by AndreyZ
You can use the following code:
Code: Select all
UniQuery.Edit;
UniQuery.FieldByName('strfld').AsString := Edit1.Text; // Edit1.Text = Sam's Restaurant
UniQuery.Post;
Posted: Thu 24 Feb 2011 22:14
by Dido
overvi wrote:
Code: Select all
Uniquery.edit;
Uniquery.fieldbyname('strfld').asstring := '''+editbox1.text+''';
uniquery.post;
if i run code above, an error occured
I have to replace every single quote in editbox1.text with 2 single quote.
Is there an easier way ?
Use QuotedStr Delphi function:
Code: Select all
Uniquery.edit;
Uniquery.fieldbyname('strfld').asstring := QuotedStr(editbox1.text);
uniquery.post;