c# - When i use ExecuteScalar command returns an empty object -
what wrong code?
when use block of code in visual studio 2008 c# curid
output value ""
, have 2 values in database should return 2...
also when run query
select ident_current('tablename')
directly in sql server management studio, returns correct value.
string curid = ""; cmd = new sqlcommand(); cmd.commandtype = commandtype.text; cmd.commandtext = "select ident_current('@tblname')"; cmd.parameters.addwithvalue("@tblname", tablename); cmd.connection = con; object obj = cmd.executescalar(); curid = obj.tostring();
edit commandtext this:
cmd.commandtext = "select ident_current(' " + tablename + "')";
Comments
Post a Comment