dapper-simplecrud


Dapper: Result from "SELECT COUNT(*) FROM TableName


I have the following code:
string sql = "SELECT COUNT(*) FROM " + tableName;
var rtn = DapperConnection.Query<int>(sql);
This works and bring back 1 record in the rtn variable. When I inspect the variable it seems to have 2 members, one is "[0]" and the other is "Raw View".
The member [0] is of type int and has the expected value, but I can't seem to get to that value in my code. This seems like a stupid question because I should be able to get to it, but can't. The latest try was the following:
int rtnCount = (int)rtn[0];
This however gave me a compiler error. How do I get to this value in my code?
Thanks
Please don't do this! It's fragile, and introduces a gaping sql injection vulnerability. If you can return your count for a given table with one line of very expressive code, and no vulnerability, why make it method?
DapperConnection.ExecuteScalar<int>("SELECT COUNT(*) FROM customers");
// You will be happier and live longer if you avoid dynamically constructing sql with string concat.
Use rtn.First() - it is an enumeration so that's the general way to get its first (and only in this case) item.

Related Links

Dapper: Result from "SELECT COUNT(*) FROM TableName

Categories

HOME
eclipse
azure-stream-analytics
string
merge
alexa-skills-kit
battery
switch-statement
hugo
square
angularfire2
frontend
rcloud
categorical-data
why3
redis-sentinel
emoji
php-5.6
endpoint
entitymanager
atlassian-stash
digital-signature
symfony-console
mapstruct
jmp
asp.net-core-webapi
monit
comparable
failover
winpe
finagle
custom-controls
cognos-bi
jmockit
dumpbin
erb
installscript
modalviewcontroller
arduino-ide
jwplayer6
zoomify
dm-script
amazon-ses
projects-and-solutions
metawidget
google-data-api
setup.py
apache-stanbol
doc
trigonometry
visa
plaintext
laravel-elixir
android-softkeyboard
knime
strftime
dapper-simplecrud
proget
openrasta
dtsearch
geotiff
twilio-click-to-call
manova
magic-draw
tinkerpop
yii2-user
excel-dna
janus
mouseleave
flac
d3-force-directed
template-toolkit
vcloud-director-rest-api
taocp
mapxtreme
adafruit
signalr.client
model-associations
eigenvector
shopping
riot
query-by-example
ellucian-scribe
contentcontrol
fiware-monitoring
ess
sql-server-data-tools
bufferedinputstream
dot.js
grouping-sets
viewer
browserify-shim
cocos3d
mdichild
with-statement
tinyxml
draw2d-js
spring-remoting
synapse
openargs
kaleidoscope
epiceditor
pagedown
pstack
kqueue
stress
hibernateexception
mysql-error-1205
lr
strtod
skype4java
tui
cardspace

Resources

Encrypt Message