Inserting specific parameters through Npgsql rather than inserting it in single line query with all the parameters which are declared inside a PostgreSQL.



 DataSet dsdata = new DataSet();
            string sqlQuery = "select * from systemtracker_dbo.sp_grp_comp_unit_data(par_p_oprtype:=" + opr_type;
            sqlQuery = sqlQuery + " ,par_p_user_id:='" + user_id + "'";
            sqlQuery = sqlQuery + " ,par_p_group_id:='" + group_id + "'";
            sqlQuery = sqlQuery + " ,par_p_comp_id:='" + comp_id + "'";
            sqlQuery = sqlQuery + " ,par_p_unit_id:='" + unit_id + "'";
            sqlQuery = sqlQuery + " ,p_refcur:='t1'";
            sqlQuery = sqlQuery + " );FETCH ALL IN t1;";
            dbHelper = new AI_Portal_Cloud.DAL.clsPSQLHelper();
            NpgsqlCommand sc = dbHelper.GetSqlQueryCommand(sqlQuery);
            dsdata = dbHelper.RemovePostGresRefCursor(dbHelper.LoadDataSet(sc));


Here the Parameters are only inserted which have their values from front end otherwise the extra parameter which are not assigned any values which are declared in PostgreSQL  function are set with some default value within the PostgreSQL  function in back end which are set to their default values when the function do not get from front end.

Also remember the format of writing the parameter value
as opr_type  is numeric type so no quotes are there
but user_id ,group_id, comp_id,unit_id   are in character varying format

Comments

Popular posts from this blog

Npgsql query and format with output parameters

Npgsql Helper class