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. Visual Basic
  4. exception

exception

Scheduled Pinned Locked Moved Visual Basic
databasetutorial
6 Posts 5 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
    santhosh padamatinti
    wrote on last edited by
    #1

    hi I established a data base connection, where I used a query sql_querry="SELECT name FROM sample_table" is displaying all values perfectly, now I want to use where condition sql_querry="SELECT name FROM sample_table WHERE"+"(Designation=SE)" But it is throwing an exception. I think this one I am getting because I am not giving query perfectly. Please tell me how to write this query. Thanx in advance...........

    sampath-padamatinti

    N H D 3 Replies Last reply
    0
    • S santhosh padamatinti

      hi I established a data base connection, where I used a query sql_querry="SELECT name FROM sample_table" is displaying all values perfectly, now I want to use where condition sql_querry="SELECT name FROM sample_table WHERE"+"(Designation=SE)" But it is throwing an exception. I think this one I am getting because I am not giving query perfectly. Please tell me how to write this query. Thanx in advance...........

      sampath-padamatinti

      N Offline
      N Offline
      nlarson11
      wrote on last edited by
      #2

      sql_querry="SELECT name FROM sample_table WHERE Designation='SE'"

      'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous

      1 Reply Last reply
      0
      • S santhosh padamatinti

        hi I established a data base connection, where I used a query sql_querry="SELECT name FROM sample_table" is displaying all values perfectly, now I want to use where condition sql_querry="SELECT name FROM sample_table WHERE"+"(Designation=SE)" But it is throwing an exception. I think this one I am getting because I am not giving query perfectly. Please tell me how to write this query. Thanx in advance...........

        sampath-padamatinti

        H Offline
        H Offline
        Henry Minute
        wrote on last edited by
        #3

        You should not use inline queries, they are dangerous and can lead to SQL Injection attacks. Before you get a bad habit ingrained into your coding style learn how to use parameterised queries (or parameterized queries, spelling differs). There is a reasonable tutorial here[^] in PDF format, although it deals with Access it covers how to convert an inline query into a parameterised one, and the principles are the same. If you don't like that one then there are plenty more examples, just google for the phrase. :)

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        1 Reply Last reply
        0
        • S santhosh padamatinti

          hi I established a data base connection, where I used a query sql_querry="SELECT name FROM sample_table" is displaying all values perfectly, now I want to use where condition sql_querry="SELECT name FROM sample_table WHERE"+"(Designation=SE)" But it is throwing an exception. I think this one I am getting because I am not giving query perfectly. Please tell me how to write this query. Thanx in advance...........

          sampath-padamatinti

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

          sampath-padamatinti wrote:

          sql_querry="SELECT name FROM sample_table WHERE"+"(Designation=SE)"

          On tpo of what everyone else said, if you look at the string you built closely, you'll see there is no space between "WHERE" and "(Designation=SE)". The resulting SQL looks like this (which is not a valid statement!):

          SELECT name FROM sample\_table **WHERE(Designation=SE)**
          

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008
          But no longer in 2009...

          L 1 Reply Last reply
          0
          • D Dave Kreskowiak

            sampath-padamatinti wrote:

            sql_querry="SELECT name FROM sample_table WHERE"+"(Designation=SE)"

            On tpo of what everyone else said, if you look at the string you built closely, you'll see there is no space between "WHERE" and "(Designation=SE)". The resulting SQL looks like this (which is not a valid statement!):

            SELECT name FROM sample\_table **WHERE(Designation=SE)**
            

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008
            But no longer in 2009...

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Dave, SQL Server parses and executes this statement. But if there was no '(' after the where clause, things would be different :-)

            D 1 Reply Last reply
            0
            • L Lost User

              Dave, SQL Server parses and executes this statement. But if there was no '(' after the where clause, things would be different :-)

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

              Shameel wrote:

              Dave, SQL Server parses and executes this statement.

              No kidding. I know that.

              Shameel wrote:

              But if there was no '(' after the where clause, things would be different

              Besides not having the "SE" in quotes, better yet, even as a SqlParameter, I like to see spaces where they are necessary and consistantly used, regardless of what the next character is.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008
              But no longer in 2009...

              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