c# - How to manipulate Database.ExecuteSqlCommand() return value? -
this question has answer here:
- why raw query count rows returns -1? 2 answers
private int getid(int userid, int companyid){ string query = string.format("select id mytable userid = {0} , companyid = {1}", userid, companyid); return _db.executesqlcommand(query); } i can run query via microsoft's sql management studio , returns 15. every time execute within code returns -1.
msdn api states:
return value
type: system.int32
the result returned database after executing command.
the description vaugue, , think how using should working. how can manipulate query return 15, or not possible? if not, have recommendations?
when executing command returns data, such 'select' statement, should consider using sqlquery method. executesqlquery regarded ddl/dml command statements 'update' not return data.
additionally, should parameterize query such this. written, it's vulnerable sql injection attacks.
Comments
Post a Comment