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. Placeholders in C#?

Placeholders in C#?

Scheduled Pinned Locked Moved C#
c++questioncsharpdatabase
3 Posts 3 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Are there anything like C++ "%s" or "%f" in C#? Essentially if you have a big query and you have 10 placeholders, what is the cleanest way of filling it up...for instance, in MFC you could do , LPCSTR lpQuery = "EXEC MySP %s, %s,%s"; CString szQuery; szQuery.Format("a", "b", "c"); which is clean and simple....how would you do something like this in c#?

    S D 2 Replies Last reply
    0
    • A Anonymous

      Are there anything like C++ "%s" or "%f" in C#? Essentially if you have a big query and you have 10 placeholders, what is the cleanest way of filling it up...for instance, in MFC you could do , LPCSTR lpQuery = "EXEC MySP %s, %s,%s"; CString szQuery; szQuery.Format("a", "b", "c"); which is clean and simple....how would you do something like this in c#?

      S Offline
      S Offline
      Steven Lyons
      wrote on last edited by
      #2

      You can do a similar thing in C# with the String.Format() method. See: http://search.microsoft.com/gomsuri.asp?n=3&c=rp\_Results& siteid=us/dev&target=http://msdn.microsoft.com/library/en-us/ cpref/html/frlrfSystemStringClassFormatTopic.asp The long and short of it is this: sQuery = String.Format("EXEC MySP {0}", sSPVariable); Steve

      1 Reply Last reply
      0
      • A Anonymous

        Are there anything like C++ "%s" or "%f" in C#? Essentially if you have a big query and you have 10 placeholders, what is the cleanest way of filling it up...for instance, in MFC you could do , LPCSTR lpQuery = "EXEC MySP %s, %s,%s"; CString szQuery; szQuery.Format("a", "b", "c"); which is clean and simple....how would you do something like this in c#?

        D Offline
        D Offline
        Daniel Turini
        wrote on last edited by
        #3

        This kind of code can lead to some bugs and security issues. If you want to keep with it or for uses other than SQL queries, use String.Format(), or, for better performance and solve the bugs I've mentioned, use classes like SqlCommand and SqlParameter. lazy isn't my middle name.. its my first.. people just keep calling me Mel cause that's what they put on my drivers license. - Mel Feik

        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