c# - How to manipulate Database.ExecuteSqlCommand() return value? -


this question has answer here:

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

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -