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. Space in table name problem

Space in table name problem

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 2 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.
  • B Offline
    B Offline
    benglish72
    wrote on last edited by
    #1

    Hi, when I try to read in data to a dataset and the table name has a space in it, I get an exception that the table doesn't exist. For some reason, only the part of the table name up to the space is recognised. Do I need to escape the space in a special way or try some other method? Thanks. ...code.... String sTable = "Table space". dataAdapter.File(dataSet,sTable); //exception here...., tries to load "Table" "Ergo huffabo et puffabo et tuam domum inflabo" ait magnus malus lupus.

    C 1 Reply Last reply
    0
    • B benglish72

      Hi, when I try to read in data to a dataset and the table name has a space in it, I get an exception that the table doesn't exist. For some reason, only the part of the table name up to the space is recognised. Do I need to escape the space in a special way or try some other method? Thanks. ...code.... String sTable = "Table space". dataAdapter.File(dataSet,sTable); //exception here...., tries to load "Table" "Ergo huffabo et puffabo et tuam domum inflabo" ait magnus malus lupus.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Spaces in database object names are a terrible idea, use _ in future. For now, I believe that wrapping the name in square brackets will fix the problem. I know that works for reserved names. If I am wrong, try single quotes, but that seems a lot less likely to me. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      B 1 Reply Last reply
      0
      • C Christian Graus

        Spaces in database object names are a terrible idea, use _ in future. For now, I believe that wrapping the name in square brackets will fix the problem. I know that works for reserved names. If I am wrong, try single quotes, but that seems a lot less likely to me. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

        B Offline
        B Offline
        benglish72
        wrote on last edited by
        #3

        Hi, thanks, it's not my data file, so I can't control the use of spaces. I've tried wrapping it in square brackets, but it still throws an exception and seems to ignore the part of the name after the space, also does this if I replace the space with an underscore, quite weird. "Ergo huffabo et puffabo et tuam domum inflabo" ait magnus malus lupus.

        B 1 Reply Last reply
        0
        • B benglish72

          Hi, thanks, it's not my data file, so I can't control the use of spaces. I've tried wrapping it in square brackets, but it still throws an exception and seems to ignore the part of the name after the space, also does this if I replace the space with an underscore, quite weird. "Ergo huffabo et puffabo et tuam domum inflabo" ait magnus malus lupus.

          B Offline
          B Offline
          benglish72
          wrote on last edited by
          #4

          Hi, that suggestion of yours worked great, I'd just put it in after the necessary place in the code. Thanks heaps. "Ergo huffabo et puffabo et tuam domum inflabo" ait magnus malus lupus.

          C 1 Reply Last reply
          0
          • B benglish72

            Hi, that suggestion of yours worked great, I'd just put it in after the necessary place in the code. Thanks heaps. "Ergo huffabo et puffabo et tuam domum inflabo" ait magnus malus lupus.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            No worries. The _ will only work if the table is named that way to start with, you can't use one for the other :-) The [] is generally a good way to show SQL what you mean when it's not clear, for example if you name a table Index, it won't work without the [] to show that the reserved word is meant as a name. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

            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