c# - SqlCommand SUM(NVL()) issue -


hello i'm trying select sum of payments got exception: nvl not recognized function name

with code:

            sqlcommand sc2 = new sqlcommand("select sum(nvl(payments,0)) sumcastka kliplat akce=" + zakce.text, spojeni);              spojeni.open();              int sumofprice = 0;             object vysledek2 = sc2.executescalar();             if (vysledek2 != dbnull.value)                 sumofprice = convert.toint32(vysledek2);            // int vysledek2 = convert.toint32(sc2.executescalar());              spojeni.close(); 

this should work when no records found column "payments" "0" if possible.

thank reading this.

this should work when no records found column "payments"

no, treat null values in payments column 0.

if no records found, executescalar returns null (not dbnull):

sqlcommand sc2 = new sqlcommand("select sum(isnull(payments,0)) sumcastka kliplat akce=" + zakce.text, spojeni);  spojeni.open();  int sumofprice = 0; object vysledek2 = sc2.executescalar(); if (vysledek2 != null && vysledek2 != dbnull.value)     sumofprice = convert.toint32(vysledek2);  spojeni.close(); 

you should using sqlparameters instead of concatenating strings, that's separate issue.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -