Hey all,


I am having a little trouble with my sql and VB.net I think

There it is I want to select records from a customer table which is like what the user types in (So they don't have to be exact matches. The statment runs but I don't think it is running correctly I stops after the first record which is the exact macth the the name I type in.
Here Is the code I am using. I just put James in instead of the text box value.

LastCus = "Select * from tblCustomer where  ((Cus_Name Like 'James'));"
            connetionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source = KellihersLawnmowers.accdb"
            cnn = New OleDbConnection(connetionString)
            cnn.Open()

            cmd = New OleDbCommand(LastCus, cnn)
            reader = cmd.ExecuteReader()


            While reader.Read()
                CustomerID = reader.Item(0)
                FoundName = reader.Item(1)
                foundNumber = reader.Item(2)
            End While
            reader.Close()
            cmd.Dispose()
            cnn.Close()

        Catch myException As Exception
      
        Finally
            reader.Close()
            cmd.Dispose()

The Codes runs find but only ever returns the exacty match.

Any Ideas?


Thanks

James

I think you need to wrap your search string with %. I regularly reference this page for SQL information and it says your statement should be as follows:
"LastCus = "Select * from tblCustomer where ((Cus_Name Like '%James%'));"

HTH

Hey Stevoni

Thanks for the fast relpy.

That was the solved my problem.

Thanks very much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.