-
October 8th, 2010, 08:53 AM
#1
Escape Ampersand in .net
Hi, I need to run execute a sql select to populate a list in my .net app.
I am using Oraclecommand as follows:
System.Data.OracleClient.OracleCommand oCmd = new OracleCommand(sQuery, oracleConn);
OracleDataReader myReader = oCmd.ExecuteReader()
However, when the name contains an ampersand, the query does not return any records.
When I execute following in SQL Plus, it works fine.
SET SCAN OFF
select * from table1 where name = 'SI&TAMB'
Any suggestions how to escape the ampersand in .net code??
-
October 11th, 2010, 06:11 AM
#2
Re: Escape Ampersand in .net
You will have to forgive me if this is wrong, but with oledb, which I use often, we simply put a "@" before the declared string. So for example:
string sql_string = @"SELECT [tbl_users.name] FROM [tbl_users] WHERE [tbl_users.name] LIKE '&'"
please bare with me if syntax is wrong, im doing this off the top of my head but it should compile fine.
also you really should think about using PARAMETERS and not directly coding into or referencing the input of objects, but I shall not preach as everyone takes short cuts.
I hope you find this helpful. If not you can shake your head and declare me a noob
Regards
-
October 11th, 2010, 06:45 AM
#3
Re: Escape Ampersand in .net
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|