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. Database & SysAdmin
  3. Database
  4. MySql - No results from query with WHERE

MySql - No results from query with WHERE

Scheduled Pinned Locked Moved Database
csharpdatabasemysqlvisual-studiocom
6 Posts 4 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
    BobbyStrain
    wrote on last edited by
    #1

    I have exhausted my resources. My application works fine with Access 2007. I have a windows form built with VS 2010 using a MySql database. Following is what I thought was the proper coding for MySql. Even if I run a simple query with a WHERE colmx = "string" no rows are returned. Only the SELECT clause is working. Can someone point me to a resource for a solution? MySql 5.7.17 MySql database on remote server. (and local) Windows C# Form VS 2010 .NET 3.5 private void txtSearchName_TextChanged(object sender, EventArgs e) { string srch = "Strain"; //txtSearchName.Text + "%"; this.contactsTableAdapter.FillByName(this.strain_family_databaseDataSet.contacts, srch); } VS 2010 DataSet Query SELECT `ID`, `Company`, `Last Name`, `First Name`, 'etc' FROM `contacts` WHERE 'Last Name' LIKE @Param1 OR 'First Name' LIKE @Param1 ORDER BY 'Last Name'

    M B 2 Replies Last reply
    0
    • B BobbyStrain

      I have exhausted my resources. My application works fine with Access 2007. I have a windows form built with VS 2010 using a MySql database. Following is what I thought was the proper coding for MySql. Even if I run a simple query with a WHERE colmx = "string" no rows are returned. Only the SELECT clause is working. Can someone point me to a resource for a solution? MySql 5.7.17 MySql database on remote server. (and local) Windows C# Form VS 2010 .NET 3.5 private void txtSearchName_TextChanged(object sender, EventArgs e) { string srch = "Strain"; //txtSearchName.Text + "%"; this.contactsTableAdapter.FillByName(this.strain_family_databaseDataSet.contacts, srch); } VS 2010 DataSet Query SELECT `ID`, `Company`, `Last Name`, `First Name`, 'etc' FROM `contacts` WHERE 'Last Name' LIKE @Param1 OR 'First Name' LIKE @Param1 ORDER BY 'Last Name'

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Errors = field names with spaces - this will drive you nuts as you now need to bracket the field names with [] try WHERE [Last Name] like @param1 etc..

      Never underestimate the power of human stupidity RAH

      J 1 Reply Last reply
      0
      • B BobbyStrain

        I have exhausted my resources. My application works fine with Access 2007. I have a windows form built with VS 2010 using a MySql database. Following is what I thought was the proper coding for MySql. Even if I run a simple query with a WHERE colmx = "string" no rows are returned. Only the SELECT clause is working. Can someone point me to a resource for a solution? MySql 5.7.17 MySql database on remote server. (and local) Windows C# Form VS 2010 .NET 3.5 private void txtSearchName_TextChanged(object sender, EventArgs e) { string srch = "Strain"; //txtSearchName.Text + "%"; this.contactsTableAdapter.FillByName(this.strain_family_databaseDataSet.contacts, srch); } VS 2010 DataSet Query SELECT `ID`, `Company`, `Last Name`, `First Name`, 'etc' FROM `contacts` WHERE 'Last Name' LIKE @Param1 OR 'First Name' LIKE @Param1 ORDER BY 'Last Name'

        B Offline
        B Offline
        Bernhard Hiller
        wrote on last edited by
        #3

        The differences in the SQL dialects of MS Access and MySQL can be terrible. It is best to avoid field / table names with blanks. If you insist on them, you must escape the name correctly, Access uses [name with blank] while MySQL `name with blank`. Next, a comparison with LIKE expects a wild card. Strain does not contain a wild card, use Strain% instead - and make sure that you have data starting with that in one of the columns...

        B 1 Reply Last reply
        0
        • M Mycroft Holmes

          Errors = field names with spaces - this will drive you nuts as you now need to bracket the field names with [] try WHERE [Last Name] like @param1 etc..

          Never underestimate the power of human stupidity RAH

          J Offline
          J Offline
          Jorgen Andersson
          wrote on last edited by
          #4

          Brackets is only on SQL Server, on MySQL you need to use the backtick ` Both supports the use of double quote " as that is the ANSI standard. You may need to SET sql_mode = 'ANSI_QUOTES' though.

          Wrong is evil and must be defeated. - Jeff Ello

          M 1 Reply Last reply
          0
          • B Bernhard Hiller

            The differences in the SQL dialects of MS Access and MySQL can be terrible. It is best to avoid field / table names with blanks. If you insist on them, you must escape the name correctly, Access uses [name with blank] while MySQL `name with blank`. Next, a comparison with LIKE expects a wild card. Strain does not contain a wild card, use Strain% instead - and make sure that you have data starting with that in one of the columns...

            B Offline
            B Offline
            BobbyStrain
            wrote on last edited by
            #5

            Bernhard, Thank you. I don't know how I missed the backtick. I kept looking for something serious. I discovered it about an hour after posting. It became obvious when I executed queries with Workbench. That is a great tool! Well, I corrected that. As to the wildcard, I had that done properly in the query I was interested in, appending the % to the string before passing to the query. The web is filled with advice on wildcards, most is incorrect. I always get answers quickly here.

            1 Reply Last reply
            0
            • J Jorgen Andersson

              Brackets is only on SQL Server, on MySQL you need to use the backtick ` Both supports the use of double quote " as that is the ANSI standard. You may need to SET sql_mode = 'ANSI_QUOTES' though.

              Wrong is evil and must be defeated. - Jeff Ello

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              Ah thanks, have not got used to the variations in MySQL yet and I would never find that wrinkle - spaces in field names are NEVER acceptable.

              Never underestimate the power of human stupidity RAH

              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