Double quotes in c#
-
Hi I have the folowing code for creating an sql query
string cmdText = ""; if (machines.Count > 0) { cmdText = @" AND CHECKINOUT.SENSORID IN ( "; int counter = 0; foreach (int itemId in machines) { cmdText += "\\"" + itemId.ToString() + "\\""; if (counter != machines.Count) { cmdText += ","; } counter ++; } cmdText += ")"; }
The \" is not working. I want to have a sort of display like ("1","2") but I am having (\"1",\"2"). Can someone help me please?
-
Hi I have the folowing code for creating an sql query
string cmdText = ""; if (machines.Count > 0) { cmdText = @" AND CHECKINOUT.SENSORID IN ( "; int counter = 0; foreach (int itemId in machines) { cmdText += "\\"" + itemId.ToString() + "\\""; if (counter != machines.Count) { cmdText += ","; } counter ++; } cmdText += ")"; }
The \" is not working. I want to have a sort of display like ("1","2") but I am having (\"1",\"2"). Can someone help me please?
All you need is
""
.
Panic, Chaos, Destruction. My work here is done.
-
Hi I have the folowing code for creating an sql query
string cmdText = ""; if (machines.Count > 0) { cmdText = @" AND CHECKINOUT.SENSORID IN ( "; int counter = 0; foreach (int itemId in machines) { cmdText += "\\"" + itemId.ToString() + "\\""; if (counter != machines.Count) { cmdText += ","; } counter ++; } cmdText += ")"; }
The \" is not working. I want to have a sort of display like ("1","2") but I am having (\"1",\"2"). Can someone help me please?
I'm more concerned that you're doing two things that are obviously wrong here. 1. You are using string for concatenation. Take a look at using StringBuilder instead. 2. There is a limit to how many items can appear in an IN clause. The limit varies from database to database, but whenever I see this architecture I shudder. It shows you're either naive about performance enhancements in the database, or lazy.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Hi I have the folowing code for creating an sql query
string cmdText = ""; if (machines.Count > 0) { cmdText = @" AND CHECKINOUT.SENSORID IN ( "; int counter = 0; foreach (int itemId in machines) { cmdText += "\\"" + itemId.ToString() + "\\""; if (counter != machines.Count) { cmdText += ","; } counter ++; } cmdText += ")"; }
The \" is not working. I want to have a sort of display like ("1","2") but I am having (\"1",\"2"). Can someone help me please?
Hi, on top of what the other chaps already said: 1. how did you establish there are backslashes present? don't trust the Visual Studio watch windows, the only thing you should really trust is your own code: try Console.WriteLine(cmdText) 2. if SENSORID is a numeric field, the values don't need any double quotes; with quotes you turn them into strings. :)
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
modified on Friday, June 12, 2009 10:01 AM