sql server - incorrect syntax near the keyword where c#? -
when run code erorr apeared incorrect syntax near keyword c#
public sqldatareader getdr(commandtype handelmode, string sqlstat, list<sqlparameter> parms) { sqldatareader r = null; sqlcommand com = new sqlcommand(); sqlconnection con = getconn(); try { com.commandtext = sqlstat; com.connection = con; com.commandtype = handelmode; if (parms != null) { foreach (sqlparameter p in parms) { com.parameters.add(p); } } r = com.executereader(commandbehavior.closeconnection); } catch (exception ex) { messagebox.show(ex.message, "error", messageboxbuttons.ok); return null; } { con.close(); } return r; }
private void picturebox10_click_2(object sender, eventargs e) { list<sqlparameter> parslist = new list<sqlparameter>(); string selectstatement = "select id,aname,ename,i_d " + screenmastertablename; string cond = " id_co=@id_co"; parslist.add(new sqlparameter("@id_co", forminfo.id_co)); if (s_id.text != "") { decimal d = 0; decimal.tryparse(s_id.text, out d); cond += " , id=@id"; parslist.add(new sqlparameter("@id", d)); } if (s_aname.text != "") { if (cond != "") cond += " , "; cond += " aname =@aname"; parslist.add(new sqlparameter("@aname", s_aname.text)); } if (s_ename.text != "") { if (cond != "") cond += " , "; cond += " ename =@ename"; parslist.add(new sqlparameter("@ename", s_ename.text)); } if (cond != "") cond = " " + cond; var l = bus.getsearcheddata(selectstatement + cond, parslist); datagridview1.datasource = l; label9.text = l.count.tostring(); }
assuming s_id filled in have query this:
where , id=@id
Comments
Post a Comment