StrataFrame Forum
Home
»
StrataFrame Application Framework - V1
»
WinForms (How do I?)
Using BO.Seek with strings and single quotes
http://forum.strataframe.net/Topic31530.aspx
By Ger Cannoll
-
10/28/2012
I have a variable called myName and its value is --> Paddy O'Sullivan
I have a MyBo.seek("Comp_name = " + "'" + myName + "'") and its erroring out, I think because of the embedded single quote in the name before Sullivan
(If I was doing this in SQL (as opposed to a BO) I'd use a Parameter so single quotes would not be a problem)
I know I cam probably get over this by replacing single quotes with adifferent character but I wont get a proper result then.
Is there any way of using e Parameter structure when I do BO.Seek ?
By Ivan George Borges
-
10/29/2012
Hi Ger.
Try:
MyBo.seek("Comp_name = " + "'" + myName.Replace("'", "''") + "'")
By Edhy Rijo
-
10/29/2012
Hi Ger, Ivan,
Since no parameter can be used in the bo.Seek() I am a big fan of using the String.Format to get my expression clearer, so I would use something like this:
Me
.MyBO.Seek(
String
.Format(
"MyName='{0}'"
,
Me
.MyBO.
MyName
.Replace(
"'"
,
"''"
)))
By Ivan George Borges
-
10/29/2012
Yep, looks good.
By Ger Cannoll
-
10/29/2012
Hi Ivan, Edhy, many thanks for your replies.
Since posting , I have discovered that doing a seek on a BO.Seek is too slow (With thousands of transactions) so I have gone back to Seeking the Database itself, and here I can use parameters anyway, so not a problem
Just one query though, If I do as seek with the replaced two single quotes, does it seek for the Single Quote or seek for two single quotes
In an example, I used a variable to hold the string (with the single quote replaced with two single quotes) , and if it was not found, it inserts it, but it inserted two single quotes !!