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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. a mistake with the "Like" statement..help!..

a mistake with the "Like" statement..help!..

Scheduled Pinned Locked Moved Database
helpdatabasedata-structurestutorialquestion
12 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.
  • K Offline
    K Offline
    keremburak
    wrote on last edited by
    #1

    dear friends, I develop an Win application by using MS Access.I have got a problem in SQL statement.I have got a form that has got 2 ComboBox and a DataGridView.The name of the first is cmbCategories and the second one is cmbContent.Content is listing the content of categories.I use an array to transfer letters when I choose the category in cmbCategories as it is Alphabetical Array.When I choose a letter from cmbContent like A,B or another one,but no records is listing in the DataGridView.I try to use "Like" statement for this action.It is like this: string strSQL = "select FilmName from films where FilmName like" + "'" + cmbContent.Text + "*'"; cmbContent has got the Alphabetical letters by sequence.I want to list the FilmName that is beginning as alphabetic.For example,when I choose letter A,the films begins A must be listed.Does anybody help me?Thanks for your help.

    B E P R D 5 Replies Last reply
    0
    • K keremburak

      dear friends, I develop an Win application by using MS Access.I have got a problem in SQL statement.I have got a form that has got 2 ComboBox and a DataGridView.The name of the first is cmbCategories and the second one is cmbContent.Content is listing the content of categories.I use an array to transfer letters when I choose the category in cmbCategories as it is Alphabetical Array.When I choose a letter from cmbContent like A,B or another one,but no records is listing in the DataGridView.I try to use "Like" statement for this action.It is like this: string strSQL = "select FilmName from films where FilmName like" + "'" + cmbContent.Text + "*'"; cmbContent has got the Alphabetical letters by sequence.I want to list the FilmName that is beginning as alphabetic.For example,when I choose letter A,the films begins A must be listed.Does anybody help me?Thanks for your help.

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      string strSQL = "select FilmName from films where FilmName like '" + cmbContent.Text + "*'";


      I Love SQL

      1 Reply Last reply
      0
      • K keremburak

        dear friends, I develop an Win application by using MS Access.I have got a problem in SQL statement.I have got a form that has got 2 ComboBox and a DataGridView.The name of the first is cmbCategories and the second one is cmbContent.Content is listing the content of categories.I use an array to transfer letters when I choose the category in cmbCategories as it is Alphabetical Array.When I choose a letter from cmbContent like A,B or another one,but no records is listing in the DataGridView.I try to use "Like" statement for this action.It is like this: string strSQL = "select FilmName from films where FilmName like" + "'" + cmbContent.Text + "*'"; cmbContent has got the Alphabetical letters by sequence.I want to list the FilmName that is beginning as alphabetic.For example,when I choose letter A,the films begins A must be listed.Does anybody help me?Thanks for your help.

        E Offline
        E Offline
        Eddie Y Chen
        wrote on last edited by
        #3

        You should use parameterized SQL commands to prevent SQL injections...:)

        K 1 Reply Last reply
        0
        • E Eddie Y Chen

          You should use parameterized SQL commands to prevent SQL injections...:)

          K Offline
          K Offline
          keremburak
          wrote on last edited by
          #4

          I tried,but it doesnt work.I wrote the whole code below.maybe it helps what I want to do. private DataView Get_DataAlphabetic() { string constr = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + Environment.CurrentDirectory + "\\mdb\\film_db.mdb"; OleDbConnection con_ole = new OleDbConnection(constr); string strSQL = "select FilmName from films where FilmName like " + "'" + cmbContent.Text + "*'"; OleDbDataAdapter da = new OleDbDataAdapter(strSQL, con_ole); DataTable dt = new DataTable(); da.Fill(dt); DataView dv = new DataView(dt); dv.Sort = "FilmName ASC"; da.Dispose(); con_ole.Close(); return dv; } I send it to a datagrid's datasource property in another method as I use cmobobox's SelectedIndexChanged method.Hope it is clear.I wait for your replies -- modified at 5:58 Monday 10th September, 2007

          a

          B 1 Reply Last reply
          0
          • K keremburak

            dear friends, I develop an Win application by using MS Access.I have got a problem in SQL statement.I have got a form that has got 2 ComboBox and a DataGridView.The name of the first is cmbCategories and the second one is cmbContent.Content is listing the content of categories.I use an array to transfer letters when I choose the category in cmbCategories as it is Alphabetical Array.When I choose a letter from cmbContent like A,B or another one,but no records is listing in the DataGridView.I try to use "Like" statement for this action.It is like this: string strSQL = "select FilmName from films where FilmName like" + "'" + cmbContent.Text + "*'"; cmbContent has got the Alphabetical letters by sequence.I want to list the FilmName that is beginning as alphabetic.For example,when I choose letter A,the films begins A must be listed.Does anybody help me?Thanks for your help.

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            zmskerem wrote:

            "*'";

            Try a percent sign (%).

            B 1 Reply Last reply
            0
            • K keremburak

              dear friends, I develop an Win application by using MS Access.I have got a problem in SQL statement.I have got a form that has got 2 ComboBox and a DataGridView.The name of the first is cmbCategories and the second one is cmbContent.Content is listing the content of categories.I use an array to transfer letters when I choose the category in cmbCategories as it is Alphabetical Array.When I choose a letter from cmbContent like A,B or another one,but no records is listing in the DataGridView.I try to use "Like" statement for this action.It is like this: string strSQL = "select FilmName from films where FilmName like" + "'" + cmbContent.Text + "*'"; cmbContent has got the Alphabetical letters by sequence.I want to list the FilmName that is beginning as alphabetic.For example,when I choose letter A,the films begins A must be listed.Does anybody help me?Thanks for your help.

              R Offline
              R Offline
              rohitsrivastava
              wrote on last edited by
              #6

              hi friend you are right there is mistake in sql please correct it right string strSQL = "select FilmName from films where FilmName like '" & cmbContent.Text & "%'" ; wrong this is your "select FilmName from films where FilmName like" + "'" + cmbContent.Text + "*'";

              B 1 Reply Last reply
              0
              • P PIEBALDconsult

                zmskerem wrote:

                "*'";

                Try a percent sign (%).

                B Offline
                B Offline
                Blue_Boy
                wrote on last edited by
                #7

                Database is Access, not SQL and condition % always return null value. Instead of % is used *


                I Love SQL

                1 Reply Last reply
                0
                • R rohitsrivastava

                  hi friend you are right there is mistake in sql please correct it right string strSQL = "select FilmName from films where FilmName like '" & cmbContent.Text & "%'" ; wrong this is your "select FilmName from films where FilmName like" + "'" + cmbContent.Text + "*'";

                  B Offline
                  B Offline
                  Blue_Boy
                  wrote on last edited by
                  #8

                  rohitsrivastava wrote:

                  right string strSQL = "select FilmName from films where FilmName like '" & cmbContent.Text & "%'" ;

                  false _________________

                  rohitsrivastava wrote:

                  wrong this is your "select FilmName from films where FilmName like" + "'" + cmbContent.Text + "*'";

                  true


                  I Love SQL

                  1 Reply Last reply
                  0
                  • K keremburak

                    I tried,but it doesnt work.I wrote the whole code below.maybe it helps what I want to do. private DataView Get_DataAlphabetic() { string constr = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + Environment.CurrentDirectory + "\\mdb\\film_db.mdb"; OleDbConnection con_ole = new OleDbConnection(constr); string strSQL = "select FilmName from films where FilmName like " + "'" + cmbContent.Text + "*'"; OleDbDataAdapter da = new OleDbDataAdapter(strSQL, con_ole); DataTable dt = new DataTable(); da.Fill(dt); DataView dv = new DataView(dt); dv.Sort = "FilmName ASC"; da.Dispose(); con_ole.Close(); return dv; } I send it to a datagrid's datasource property in another method as I use cmobobox's SelectedIndexChanged method.Hope it is clear.I wait for your replies -- modified at 5:58 Monday 10th September, 2007

                    a

                    B Offline
                    B Offline
                    Blue_Boy
                    wrote on last edited by
                    #9

                    Why you aren't trying to use Filter instead of getting directrly from database. Download all data at first time from database then use filter property.


                    I Love SQL

                    K 1 Reply Last reply
                    0
                    • K keremburak

                      dear friends, I develop an Win application by using MS Access.I have got a problem in SQL statement.I have got a form that has got 2 ComboBox and a DataGridView.The name of the first is cmbCategories and the second one is cmbContent.Content is listing the content of categories.I use an array to transfer letters when I choose the category in cmbCategories as it is Alphabetical Array.When I choose a letter from cmbContent like A,B or another one,but no records is listing in the DataGridView.I try to use "Like" statement for this action.It is like this: string strSQL = "select FilmName from films where FilmName like" + "'" + cmbContent.Text + "*'"; cmbContent has got the Alphabetical letters by sequence.I want to list the FilmName that is beginning as alphabetic.For example,when I choose letter A,the films begins A must be listed.Does anybody help me?Thanks for your help.

                      D Offline
                      D Offline
                      DerekFL
                      wrote on last edited by
                      #10

                      Use "%" instead of "*"

                      1 Reply Last reply
                      0
                      • B Blue_Boy

                        Why you aren't trying to use Filter instead of getting directrly from database. Download all data at first time from database then use filter property.


                        I Love SQL

                        K Offline
                        K Offline
                        keremburak
                        wrote on last edited by
                        #11

                        thanks buddy maybe sometimes you must look at it in a true point.I have done it. Thnx.

                        a

                        B 1 Reply Last reply
                        0
                        • K keremburak

                          thanks buddy maybe sometimes you must look at it in a true point.I have done it. Thnx.

                          a

                          B Offline
                          B Offline
                          Blue_Boy
                          wrote on last edited by
                          #12

                          You are welcome...


                          I Love SQL

                          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