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. Web Development
  3. ASP.NET
  4. problem in SELECT statement

problem in SELECT statement

Scheduled Pinned Locked Moved ASP.NET
help
12 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.
  • H Offline
    H Offline
    h ma
    wrote on last edited by
    #1

    in my windows form,for search,two combo boxes are provided.the first one gives the table names and in second combo box the respective fields are provided ,by selecting any field the user enters the required value according to which te search is done i m storing both tablename and field name in string now in my select statement when i append the string with field name (with hard coded table name); it functions well but when i concatenate string having table name it gives errors..

    $h@ma!|@

    A 1 Reply Last reply
    0
    • H h ma

      in my windows form,for search,two combo boxes are provided.the first one gives the table names and in second combo box the respective fields are provided ,by selecting any field the user enters the required value according to which te search is done i m storing both tablename and field name in string now in my select statement when i append the string with field name (with hard coded table name); it functions well but when i concatenate string having table name it gives errors..

      $h@ma!|@

      A Offline
      A Offline
      Abolfazl Sheikhloo
      wrote on last edited by
      #2

      say me your error to check it.

      We Can Do Anything, If We Want It

      H 1 Reply Last reply
      0
      • A Abolfazl Sheikhloo

        say me your error to check it.

        We Can Do Anything, If We Want It

        H Offline
        H Offline
        h ma
        wrote on last edited by
        #3

        if(combobox2.text==" teachers name") str="t_name"; //giving field name //many if statements here strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE tbl1." + str + "=" + textBox1.Text+"AND tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id "; it works but when i do //tablename=combobox1.text; //or tablename="tbl1"; strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE" + tablename + "." + str + "=" + textBox1.Text+"AND tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id "; it gives error

        $h@ma!|@

        S I 2 Replies Last reply
        0
        • H h ma

          if(combobox2.text==" teachers name") str="t_name"; //giving field name //many if statements here strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE tbl1." + str + "=" + textBox1.Text+"AND tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id "; it works but when i do //tablename=combobox1.text; //or tablename="tbl1"; strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE" + tablename + "." + str + "=" + textBox1.Text+"AND tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id "; it gives error

          $h@ma!|@

          S Offline
          S Offline
          Sathesh Sakthivel
          wrote on last edited by
          #4

          what error?

          Regards, Satips.:rose: Don't walk in front of me, I may not follow; Don't walk behind me, I may not lead; Walk beside me, and just be my friend. - Albert Camus

          H 1 Reply Last reply
          0
          • S Sathesh Sakthivel

            what error?

            Regards, Satips.:rose: Don't walk in front of me, I may not follow; Don't walk behind me, I may not lead; Walk beside me, and just be my friend. - Albert Camus

            H Offline
            H Offline
            h ma
            wrote on last edited by
            #5

            some exception is handled at runtime

            $h@ma!|@

            S 1 Reply Last reply
            0
            • H h ma

              some exception is handled at runtime

              $h@ma!|@

              S Offline
              S Offline
              Sathesh Sakthivel
              wrote on last edited by
              #6

              use try catch and catch the exxception

              Regards, Satips.:rose: Don't walk in front of me, I may not follow; Don't walk behind me, I may not lead; Walk beside me, and just be my friend. - Albert Camus

              1 Reply Last reply
              0
              • H h ma

                if(combobox2.text==" teachers name") str="t_name"; //giving field name //many if statements here strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE tbl1." + str + "=" + textBox1.Text+"AND tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id "; it works but when i do //tablename=combobox1.text; //or tablename="tbl1"; strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE" + tablename + "." + str + "=" + textBox1.Text+"AND tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id "; it gives error

                $h@ma!|@

                I Offline
                I Offline
                Imran Khan Pathan
                wrote on last edited by
                #7

                strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE" + tablename + "." + str + "=" + &textBox1.Text+"AND tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id "; "AND" operator will be join with Textbox1.Text so give spance there Best Regard Pathan

                GOD HELP THOSE WHO HELP THEMSELVES

                I H 2 Replies Last reply
                0
                • I Imran Khan Pathan

                  strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE" + tablename + "." + str + "=" + &textBox1.Text+"AND tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id "; "AND" operator will be join with Textbox1.Text so give spance there Best Regard Pathan

                  GOD HELP THOSE WHO HELP THEMSELVES

                  I Offline
                  I Offline
                  Imran Khan Pathan
                  wrote on last edited by
                  #8

                  strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE " + tablename + "." + str + "=" + textBox1.Text+" AND tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id "; User this string best Regard Pathan

                  GOD HELP THOSE WHO HELP THEMSELVES

                  1 Reply Last reply
                  0
                  • I Imran Khan Pathan

                    strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE" + tablename + "." + str + "=" + &textBox1.Text+"AND tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id "; "AND" operator will be join with Textbox1.Text so give spance there Best Regard Pathan

                    GOD HELP THOSE WHO HELP THEMSELVES

                    H Offline
                    H Offline
                    h ma
                    wrote on last edited by
                    #9

                    still no progress!!:(

                    $h@ma!|@

                    I 1 Reply Last reply
                    0
                    • H h ma

                      still no progress!!:(

                      $h@ma!|@

                      I Offline
                      I Offline
                      Imran Khan Pathan
                      wrote on last edited by
                      #10

                      check this also "tbl.t_id=tbl3.tb3_id" What is tbl? Best Regard Pathan

                      GOD HELP THOSE WHO HELP THEMSELVES

                      H 1 Reply Last reply
                      0
                      • I Imran Khan Pathan

                        check this also "tbl.t_id=tbl3.tb3_id" What is tbl? Best Regard Pathan

                        GOD HELP THOSE WHO HELP THEMSELVES

                        H Offline
                        H Offline
                        h ma
                        wrote on last edited by
                        #11

                        well tbl is the tablename in databases..actually these are not the actual tablenames but it was to simplify the query to post

                        $h@ma!|@

                        N 1 Reply Last reply
                        0
                        • H h ma

                          well tbl is the tablename in databases..actually these are not the actual tablenames but it was to simplify the query to post

                          $h@ma!|@

                          N Offline
                          N Offline
                          Not Active
                          wrote on last edited by
                          #12

                          I've always found using string.format rather than concatentation helps to simplify things like this and makes the code more readable so you can find syntax errors better. Of course using a stored proc, as you should, this is not an issue.


                          only two letters away from being an asset

                          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