c# - convert this code to linq -


please convert code linq

"select * tell name 'n%" + textbox1.text + "'" 

edit: given "answer" you've posted, looks maybe want contains instead. it's helpful take time in explaining you're trying in question - see question-writing guide advice.

so may want:

var query = list.where(item => item.name.contains(textbox1.text)); 

looks me like:

var query = item in db.tell             item.name.startswith("n") && item.name.endswith(textbox1.text)             select item; 

that's if meant query wrote. if include "n" in attempt make unicode string, want:

var query = item in db.tell             item.name.endswith(textbox1.text)             select item; 

another alternative - if you're using linq sql - use sqlmethods.like:

var query = item in db.tell             sqlmethods.like(item.name, "n%" + textbox1.text)             select item; 

you can use "fluent notation" or "dot notation" instead of query expression, of these. example, last 1 equivalent to:

var query = db.tell.where(item => sqlmethods.like(item.name,                                                   "n%" + textbox1.text)); 

and first 1 equivalent to:

var query = db.tell.where(item => item.name.endswith(textbox1.text)); 

or if you're using list<t>, like:

var query = list.where(item => item.name.endswith(textbox1.text)); 

note if you're using code posted, you've got sql injection vulnerability - never create sql using user-entered data directly. use parameterized queries instead - or linq use parameterized query you.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -