c# - Select SUM if NULL - UPDATE "0" -
i have got code selects sum
, update
result somewhere. issue when there no results found select sum(castka)
conditions.
i'm wondering how make exception dbnull
if there wasn't found result , update "0"
instead. i'm not long programming please me solve out?
thank time.
private void btn_zavri_click(object sender, eventargs e) { try { spojeni.close(); sqlcommand sc2 = new sqlcommand("select sum(castka) sumcastka kliplat akce='" + zakce.text + "' , rocnik='" + rocnik + "'", spojeni); spojeni.open(); int vysledek2 = convert.toint32(sc2.executescalar()); sqlcommand sc3 = new sqlcommand("update zajezd set s_prijmy=@s_prijmy akce='" + zakce.text + "' , rocnik='" + rocnik + "'", spojeni); spojeni.close(); sc3.parameters.addwithvalue("@s_prijmy", vysledek2); spojeni.open(); sc3.executenonquery(); } catch (exception ex) { messagebox.show("" + ex); } { spojeni.close(); this.close(); } }
is want achieve?
select isnull(sum(castka), 0) sumcastka kliplat
Comments
Post a Comment