I have this simple and working well SQL-row:
MyCommand = New SqlDataAdapter("SELECT * From Tbl_Table where Type = '" & TestType.tostring & "' ", MyConnection)
----
Then I have this one which I am very proud of because I can retrieve any word or part of word from the Item-field:
Test_Text=(Session("session-Text").tostring)
Dim val1, val2, val3 as string
val1 = Test_Text
val2 = "%"
val3= val1 + val2
MyCommand = New SqlDataAdapter("SELECT * From Tbl_Table where Item Like '%" & val1 & " %' OR Item Like '%" & val3 & " %' ", MyConnection)
----
The problem is:
When I try to merge these two in one big "AND" row as shown below, It only cares of picking up the Test_Text string and ignores totaly the TestType one!
I guess it is a matter of punctuation, can any one help me? Thanks.
MyCommand = New SqlDataAdapter("SELECT * From Tbl_Table where Type = '" & TestType.tostring & "' AND Item Like '%" & val1 & " %' OR Item Like '%" & val3 & " %'", MyConnection)I fixed it like this:
MyCommand = New SqlDataAdapter("SELECT * From tbl_Table where Item Like '" & val1 & " %' OR Item Like '%" & val3 & "' AND Type = '" & TestType.tostring & "' ", MyConnection)
Thanks|||when i'm debugging a concatenated sql string like that, i usually dim a var and set the var to the string. then i can see the result of the concatenation before passing it to the command object. it helps me to pick out the syntax errs quicker...
i.e.
dim mySQL as string = "SELECT * From tbl_Table where Item Like '" & val1 & " %' OR Item Like '%" & val3 & "' AND Type = '" & TestType.tostring & "' "
MyCommand = New SqlDataAdapter(mySQL, MyConnection)|||That´s a good Idea, thanks!