Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Double quotes in c#

Double quotes in c#

Scheduled Pinned Locked Moved C#
databasecsharphelpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jonhbt
    wrote on last edited by
    #1

    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?

    N P L 3 Replies Last reply
    0
    • J jonhbt

      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?

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      All you need is "".


      Panic, Chaos, Destruction. My work here is done.

      1 Reply Last reply
      0
      • J jonhbt

        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?

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        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.

        My blog | My articles | MoXAML PowerToys | Onyx

        1 Reply Last reply
        0
        • J jonhbt

          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?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups