|
Post by jayantha on Jan 13, 2023 17:48:47 GMT
I created search function and it works nicely
var results = dbase.Query<SimpleSQL.Demos.cus>("SELECT name FROM cus WHERE name LIKE 'J%'");
foreach (var result in results)
nameTxt.text += result.name + "\n";
this display all the names in the colomn(name) that starts with the letter "J" I am really happy with result . -------------------------------------------------------------------------------------------------------------------------------------------------------------
Then I tried to input the letter J through inputfield(because then user can search for custom data)
var searchword = search.text;(through input field) var results = dbase.Query<SimpleSQL.Demos.cus>("SELECT name FROM cus WHERE name LIKE 'searchword%'");
foreach (var result in results)
nameTxt.text += result.name + "\n";
Then I assigned to a button (as public void function ) but I did not get same results as previous one(console does not show errors also).Please help me any idea. Because this is very important then user can search for custom data.Later I found details that how to use the word "LIKE " in FAQ but I want user to give an opportunity to enter search word through INPUT TEXT FIELD
|
|
|
Post by echo17 on Jan 15, 2023 22:57:43 GMT
Please see this FAQ: link
|
|
|
Post by jayantha on Jan 15, 2023 23:33:22 GMT
Yes I checked it(FAQ: link) and it worked for me.but I want to type the word in a inputfield and then get the result .
var searchword = search.text;(through input field) var results = dbase.Query<SimpleSQL.Demos.cus>("SELECT name FROM cus WHERE name LIKE 'searchword%'");
This does not give errors or result expected.
|
|
|
Post by echo17 on Jan 16, 2023 10:25:05 GMT
Your query is going to return anything with a literal word searchWord in it, not the value of the variable called searchWord. Please re-read through the link I sent again. It shows how to use parameters that you can use to substitute variable values into your string.
|
|
|
Post by jayantha on Jan 16, 2023 11:48:00 GMT
How I solved
var searchword = search.text;
var results = dbase.Query<SimpleSQL.Demos.cus>("SELECT name,id,title FROM cus WHERE name LIKE '" + searchword + "%'" );
|
|
|
Post by echo17 on Jan 17, 2023 13:05:24 GMT
That is one way to accomplish getting a variable value into your string, but I would discourage string concatenation because it can lead to strange errors that are hard to track down. I would encourage you to use parameters as they are much simpler to use and troubleshoot. Please see the link I sent for more information on how to use them.
|
|