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

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -