Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C# Programming

problem with Select in datatable


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
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+ "'");

-----------------------------------------------Reply-----------------------------------------------
I tried that but that dosen't work either.
<MarcuEuse@gmail.com> wrote in message

news:1180512777.596148.41010@p47g2000hsd.googlegroups.com...

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...

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc