c# - Select from multiple tables? -
i 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
Post a Comment