c# - Select from multiple tables? -


enter image description herei have 2 tables 1 table's name (memberform) , has columns id,name,mobile example 1,dimitris,69xxxxxxx, , second table (groups) columns name,groupname,memberid example dimitris,dancegroup,1 (memberid same id) want extract richtextbox groupname groups = combobox1 , memberid row groupname exists same memberform.id

i'm trying this

using (var command = new sqlcommand("select mobile memberform memberform.id=groups.memberid , groups.groupname='" + combobox1.text + "'", con)) //  using (var reader = command.executereader()) 

the raw sql query

select m.mobile  memberform m  join groups g on g.memberid = m.id  g.groupname = 'dancegroup' 

the same can written in sqlcommand

using (var command = new sqlcommand("select m.mobile memberform m join groups g on g.memberid = m.id g.groupname = '" + combobox1.text + "'", con)) 

update:

the above approach can possible sql injection attack, explicitly pass parameter sqlparameter

using (var command = new sqlcommand("select m.mobile memberform m join groups g on g.memberid = m.id g.groupname = @groupname", con)) {     command.parameters.add(new sqlparameter("groupname", combobox1.text);     using (var reader = command.executereader())     .... 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -