Results 1 to 8 of 8
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I hope this forum is correct. I am struggling with changing a line of SQL being used in VB.Net. I am trying to change the line to include the Like syntax. The line is :

    Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM TXMasters WHERE TXMasters.Barcode='" & Search2.Text & "'", con)

    Many thanks

    PS I like the new site, looks very good!!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Does this do what you want?

    Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM TXMasters WHERE TXMasters.Barcode Like '*" & Search2.Text & "*'", con)

    It's possible that you have to use % instead of * as wildcard, in that case, use

    Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM TXMasters WHERE TXMasters.Barcode Like '%" & Search2.Text & "%'", con)

  3. #3
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by HansV View Post
    Does this do what you want?

    Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM TXMasters WHERE TXMasters.Barcode Like '*" & Search2.Text & "*'", con)

    It's possible that you have to use % instead of * as wildcard, in that case, use

    Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM TXMasters WHERE TXMasters.Barcode Like '%" & Search2.Text & "%'", con)

    Many thanks Hans, trust your well. The second suggestion works perfectly, the first did not work so you are correct in thinking twice. Wish everything was the same but that would be too easy. Best regards

  4. #4
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Both ADODB and .NET use SQL rather than Access own hybrid,
    so Wild Card Operators are always % NOT *
    and also _ Not ?.


    You should also use ' as the text delimiter rather than the more standard " in Access

    Select * From tblMine Where Surname="Bob" would fail

    Select * From tblMine Where Surname='Bob' would be OK.


    Andrew

  5. #5
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Andrew. It's getting more and more complicated as things progress. I am now playing around with Visual Basic 2008 Express and MySql. It becomes so difficult knowing where to put questions within forums. I will remember your advice, thanks. Regards

  6. #6
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by ZOR View Post
    Thanks Andrew. It's getting more and more complicated as things progress. I am now playing around with Visual Basic 2008 Express and MySql. It becomes so difficult knowing where to put questions within forums. I will remember your advice, thanks. Regards
    I'd be interested to know how you get on with MYSQL and VB Express 2008.
    VB Express seems to have limitations regarding connecting databases (unless you code the connections).
    I am just looking into a project with VB Net and MYSQL, but think I may well have to get
    Visual Studio rather than express.

    Worth posting on the VB Net Forum though
    Andrew

  7. #7
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Boy am I struggling. There is a MySql connector that you can download to enable VB Express 2008 to connect to MySql. I am really struggling as I say because I am spending so much time trying to get forums that are lively to get answers. The whole technology I think has gone mad. I go though lots of sites only to find ASP, C+, Java, etc methods of doing things. I started off quickly I thought and then ran into a brick wall. In the past I worked with VB6, but the syntax and procedures are like a foreign language again. I think Microsoft wants us all to go down the road of using SQL Server. I watched a video on using Visual Studio connecting to SQL server, it all seemed very easy to build a database. However I never got hold of the Visual Studio 2008 Express which was free, and the Microsoft site seems to have dropped it but suggesting Visual Studio 2010 Beta (to try). Don't like the words to try, and wondered if it was another MS product that they decide when to kill it to make you buy it. I am not going to go down that road. So on I go wasting so much time. As you say, VB Express lends itself to connecting to Access and SQL Server, MySql is for those to find out things for themselves. Another thing I am finding is there are so many deviations on syntax to get the same thing, so you end up with bits and pieces that are difficult to understand and connect the next bit to. All I can say is good luck. Maybe you will get on better than me. Regards

  8. #8
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I got this working, BUT it appears to be all code for connections rather than via the VBE.

    Have a look at my thread

    http://www.wopr.com/...howtopic=767971

    Once I referenced the MYSQL Connector in the project the code worked just fine.
    Andrew

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •