Query SQL DB from VB.NET
-
Hello, I am playing with ways to set query command in VB.NET to retrieve set of records from SQL DB. I know basic sytanx and it works well. However I can not get this to work. I have a textbox where users enters a name of broker and then when clicks Search button, data grid gets populated with all broker info. This works well if name that user entered exists in SQL DB. My goal was to have this same result, but when users enters partial name too. Example: Full broker name: Mike Tyson Partial broker name: Mi This is the string I used but it does not work: Dim strSQL As String = "SELECT * FROM broker where name like '" & strName& "%'" This returns error : Index was outside the bounds of the array. If I enter this command directly in SQL Analyzer as SELECT * FROM broker where name like 'Mi%' it works just fine. What I am missing???
-
Hello, I am playing with ways to set query command in VB.NET to retrieve set of records from SQL DB. I know basic sytanx and it works well. However I can not get this to work. I have a textbox where users enters a name of broker and then when clicks Search button, data grid gets populated with all broker info. This works well if name that user entered exists in SQL DB. My goal was to have this same result, but when users enters partial name too. Example: Full broker name: Mike Tyson Partial broker name: Mi This is the string I used but it does not work: Dim strSQL As String = "SELECT * FROM broker where name like '" & strName& "%'" This returns error : Index was outside the bounds of the array. If I enter this command directly in SQL Analyzer as SELECT * FROM broker where name like 'Mi%' it works just fine. What I am missing???