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. Long SQL statement on a couple of lines

Long SQL statement on a couple of lines

Scheduled Pinned Locked Moved C#
databasetutoriallearning
6 Posts 6 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.
  • S Offline
    S Offline
    steve_rm
    wrote on last edited by
    #1

    Hello I have a SQL statement which is long. How do l write it so that it is on serveral lines. This is what l have tried to do. CnnStr = "SELECT student.studentID, student.FirstName, student.LastName" + "book.bookID, book.Title" + "FROM student, book" + "WHERE student.studentID = book.studentID"; This does not work, and anyone tell me how to do this. Many thanks in advance, Steve

    S B D A A 5 Replies Last reply
    0
    • S steve_rm

      Hello I have a SQL statement which is long. How do l write it so that it is on serveral lines. This is what l have tried to do. CnnStr = "SELECT student.studentID, student.FirstName, student.LastName" + "book.bookID, book.Title" + "FROM student, book" + "WHERE student.studentID = book.studentID"; This does not work, and anyone tell me how to do this. Many thanks in advance, Steve

      S Offline
      S Offline
      Stanciu Vlad
      wrote on last edited by
      #2

      add at the beginig and end of an string a space (0x20 char) your code needs to look like this in order to work CnnStr = " SELECT student.studentID, student.FirstName, student.LastName " + " book.bookID, book.Title " + " FROM student, book " + " WHERE student.studentID = book.studentID "; I hope you understand... By the way... visit http://nehe.gamedev.net[^]

      1 Reply Last reply
      0
      • S steve_rm

        Hello I have a SQL statement which is long. How do l write it so that it is on serveral lines. This is what l have tried to do. CnnStr = "SELECT student.studentID, student.FirstName, student.LastName" + "book.bookID, book.Title" + "FROM student, book" + "WHERE student.studentID = book.studentID"; This does not work, and anyone tell me how to do this. Many thanks in advance, Steve

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

        You're missing a comma after Student.LastName -- Help me! I'm turning into a grapefruit! Phoenix Paint - back from DPaint's ashes!

        1 Reply Last reply
        0
        • S steve_rm

          Hello I have a SQL statement which is long. How do l write it so that it is on serveral lines. This is what l have tried to do. CnnStr = "SELECT student.studentID, student.FirstName, student.LastName" + "book.bookID, book.Title" + "FROM student, book" + "WHERE student.studentID = book.studentID"; This does not work, and anyone tell me how to do this. Many thanks in advance, Steve

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          To consolidate the above answers:

          CnnStr = "SELECT student.studentID, student.FirstName, student.LastName," +
          " book.bookID, book.Title" +
          " FROM student, book" +
          " WHERE student.studentID = book.studentID";

          RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          • S steve_rm

            Hello I have a SQL statement which is long. How do l write it so that it is on serveral lines. This is what l have tried to do. CnnStr = "SELECT student.studentID, student.FirstName, student.LastName" + "book.bookID, book.Title" + "FROM student, book" + "WHERE student.studentID = book.studentID"; This does not work, and anyone tell me how to do this. Many thanks in advance, Steve

            A Offline
            A Offline
            alphanorm
            wrote on last edited by
            #5

            This may be a dumb question, but does your statement work when it is just one long line? alphanorm

            1 Reply Last reply
            0
            • S steve_rm

              Hello I have a SQL statement which is long. How do l write it so that it is on serveral lines. This is what l have tried to do. CnnStr = "SELECT student.studentID, student.FirstName, student.LastName" + "book.bookID, book.Title" + "FROM student, book" + "WHERE student.studentID = book.studentID"; This does not work, and anyone tell me how to do this. Many thanks in advance, Steve

              A Offline
              A Offline
              Alvaro Mendez
              wrote on last edited by
              #6

              Three things: 1. You need to leave the proper spaces between things like Title and FROM. 2. You need to add a comma after LastName. 3. You can also use the @ sign in front of the string to avoid the extra quotes and + signs: CnnStr = @"SELECT student.studentID, student.FirstName, student.LastName, book.bookID, book.Title FROM student, book WHERE student.studentID = book.studentID"; Regards, Alvaro


              Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we. - George W. Bush

              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