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
Post a Comment