I tried that but that dosen't work either.
<MarcuEuse
@gmail.com> wrote in message
news:1180512777.596148.41010@p47g2000hsd.googlegroups.com...
> On May 30, 9:48 am, "perspolis" <reza
@hotmail.com> wrote:
>> Hi all
>> I want to select from a datatable like below:
>> mydatatable.Select("Name='"+this.textbox1.Text+ "'");
>> it works properly but when I edit textbox1 with something like this
>> re'fd
>> that contains ' or " the Select gives me an error "Missing Operand".
>> how can I solve this problem.
>> thanks in advance
> Try using the @ like this :
> mydatatable.Select(@"Name='"+this.textbox1.Text+ "'");
Perspolis - you need to "escape" the single quotes in query filters in order
for them to be interpreted correctly.
Here's a method I use for querying with strings.
public string ToSqlString(string value, bool emptyStringIsNull)
{
if(value != null && (!emptyStringIsNull || value.Length > 0))
{
return "'" + value.Replace("'", "''") + "'";
}
else
{
return "NULL";
}
}
Then you could query your datatable as such...
mydatatable.Select("Name=" + ToSqlString(this.textbox1.Text));
Hope that helps.
--
Gregg Walker
-----------------------------------------------Reply-----------------------------------------------
thanks
"Gregg Walker" <x
@newsgroup.nospam> wrote in message
news:eO70O%23soHHA.4424@TK2MSFTNGP03.phx.gbl...
> Perspolis - you need to "escape" the single quotes in query filters in
> order for them to be interpreted correctly.
> Here's a method I use for querying with strings.
> public string ToSqlString(string value, bool emptyStringIsNull)
> {
> if(value != null && (!emptyStringIsNull || value.Length > 0))
> {
> return "'" + value.Replace("'", "''") + "'";
> }
> else
> {
> return "NULL";
> }
> }
> Then you could query your datatable as such...
> mydatatable.Select("Name=" + ToSqlString(this.textbox1.Text));
> Hope that helps.
> --
> Gregg Walker