PC Review


Reply
Thread Tools Rate Thread

Re: SQL - Search a String

 
 
A_PK
Guest
Posts: n/a
 
      24th Dec 2004
if my strCustName consist of symbol like "&" and others ??

there is a way to treat strCustName as a String, I just forget the way of
doing it.

Just treat that every value of strCustName as a whole string...


"Manuel Meitinger" <(E-Mail Removed)> wrote in message
news:41ca82b0$(E-Mail Removed)...
>> the strCustName is a dynamic field, choosen from a List of Companies.
>>
>> then I got one select statement....
>> "Select * from TableTranasction where CustName = 'strCustName'"
>>
>> The above query work perfectly for ABC Trading and XXX Company, but when
>> user choose Peter's Company, then my above mentioned query will encounter
>> problem.
>>

>
>
> Peter answered your question already!
>
> AFTER obtaining strCustName AND BEFORE making the query, replace every ` '
> ` in strCustName with two ` ' ` (that is ` '' `)
>
> ( BTW, I do believe your code rather looks like "Select * from
> TableTranasction where CustName = '" + strCustName + "'" )
>



 
Reply With Quote
 
 
 
 
Sergey Bogdanov
Guest
Posts: n/a
 
      24th Dec 2004
I recomend you to use named parameters instead:

SqlCommand sc = new SqlCommand("Select * from TableTranasction where
CustName = @CustName");
sc.Parameters.Add("@CustName", userInput);

Sergey


A_PK wrote:
> if my strCustName consist of symbol like "&" and others ??
>
> there is a way to treat strCustName as a String, I just forget the way of
> doing it.
>
> Just treat that every value of strCustName as a whole string...
>
>
> "Manuel Meitinger" <(E-Mail Removed)> wrote in message
> news:41ca82b0$(E-Mail Removed)...
>
>>>the strCustName is a dynamic field, choosen from a List of Companies.
>>>
>>>then I got one select statement....
>>>"Select * from TableTranasction where CustName = 'strCustName'"
>>>
>>>The above query work perfectly for ABC Trading and XXX Company, but when
>>>user choose Peter's Company, then my above mentioned query will encounter
>>>problem.
>>>

>>
>>
>>Peter answered your question already!
>>
>>AFTER obtaining strCustName AND BEFORE making the query, replace every ` '
>>` in strCustName with two ` ' ` (that is ` '' `)
>>
>>( BTW, I do believe your code rather looks like "Select * from
>>TableTranasction where CustName = '" + strCustName + "'" )
>>

>
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
search for string of contacts by a string of email addresses Kerm Rudgeon Microsoft Outlook Contacts 2 21st Oct 2008 08:51 PM
string/regex: extracting the context of a string match around the found search term? Microsoft C# .NET 3 5th Jul 2007 03:55 PM
to search for a string and affect data if it finds the string? =?Utf-8?B?U2h3YW1hbg==?= Microsoft Excel Worksheet Functions 1 11th Jan 2006 01:56 AM
search a string withing a string : find / search hangs itarnak Microsoft Excel Programming 4 24th Oct 2005 04:19 PM
Search and replace string in formula with string from cell Ingar Microsoft Excel Worksheet Functions 2 3rd Nov 2003 02:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:40 AM.