Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi have a query its returning text that text i am trying to store it in string but i am getting nothing in variable.

query:
SQL
CREATE OR REPLACE FUNCTION fngetlastcodeofvillage(
    text,
    text,
    text)
  RETURNS text AS
$BODY$
    DECLARE 
   
    schoolcode text;
      BEGIN
      SELECT schcd into schoolcode FROM villagerural_school_form  where districtna=$1 and talukname=$2 and villagenam=$3 order by id desc limit 1;
      IF schoolcode IS NULL THEN
        return (select census2011||'01' from villagerural b where b.districtna=$1 and b.talukname=$2 and b.villagenam=$3);
       else
        return (cast(cast(schoolcode as bigint)+1 as text ));
     END IF;
end
 $BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION fngetlastcodeofvillage(text, text, text)
  OWNER TO postgres;


above query i am calling in asp.net like
C#
public string Getschoolcodebyddl(String districtna, String talukname, String villagename)
        {

            return Helper.ExecuteSelectCommand("select * from fngetlastcodeofvillage('" + districtna + "','" + talukname + "','" + villagename + "');", CommandType.Text).ToString();
        }


can any one tell what is wrong i am doing here.query is executing pgsql getting write value but why i am not getting returned text

What I have tried:

i have tried by returning as table and setof text
Posted
Updated 6-Apr-16 23:58pm
v3
Comments
phil.o 7-Apr-16 5:49am    
"select * from fngetlastcodeofvillage4('" + districtna + "','" + talukname + "','" + villagename + "');"
Can you explain the purpose of this code piece? It seems plain wrong.
Veena Hosur 7-Apr-16 5:57am    
i am calling fngetlastcodeofvillage function from postgresql by passing districtna,talukname,villagename
phil.o 7-Apr-16 6:00am    
"select fngetlastcodeofvillage4('" + districtna + "','" + talukname + "','" + villagename + "');"?
Veena Hosur 7-Apr-16 6:02am    
i am selecting all return values from that function right?
phil.o 7-Apr-16 6:06am    
As far as I can see, this function only returns one textual value.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900