c# - Error Specified cast is not valid -


i have below function

sqlconnection cn = new sqlconnection(constring); cn.open(); sqlcommand cmd = new sqlcommand("select max(id) ep_patterns ", cn); int h = (int)cmd.executescalar() + 1; txtid.text = h.tostring(); cn.close(); 

how fix error:

specified cast not valid.

given code feel easiest way fix logic edit sql to

select isnull(max(id),0) ep_patterns 

to better understand can run sql in ssms:

declare @table table (id int); select max(id) @table; select isnull(max(id), 0) @table; 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -